From 2edc7c61af0d390c1e2e84d775f3d88b8ba34f40 Mon Sep 17 00:00:00 2001 From: Fraser Graham Date: Fri, 18 Oct 2013 20:40:09 -0700 Subject: [PATCH] fixing bug where heading can be 0 --- player.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/player.go b/player.go index dc6d931..dc43e26 100644 --- a/player.go +++ b/player.go @@ -95,13 +95,18 @@ func (p *player) nudge(g *game) { // We may have been stopped before this and had no heading current_heading = p.Robot.MoveTo.Sub(p.Robot.Position).Normalize() } + + // Where do we WANT to be heading? new_heading := p.Robot.MoveTo.Sub(p.Robot.Position).Normalize() + // Is our direction change too much? Hard coding to 5 degrees/s for now angle := v.Angle(current_heading, new_heading) * v.Rad2deg dir := 1.0 if angle < 0 { dir = -1.0 } + + // Max turn radius in this case is 100 degrees per second if math.Abs(angle) > (100 * delta) { // New heading should be a little less, take current heading and // rotate by the max turn radius per frame. @@ -120,7 +125,11 @@ func (p *player) nudge(g *game) { p.Robot.Heading = v.Vector2d{X: 0, Y: 0} } else { p.Robot.Position = p.Robot.Position.Add(move_vector) - p.Robot.Heading = new_heading + if new_heading.Mag() > 0 { + p.Robot.Heading = new_heading + } else { + log.Printf("Zero Heading %v", new_heading) + } } }