fixing bug where heading can be 0
This commit is contained in:
parent
e02c5f89fb
commit
2edc7c61af
@ -95,13 +95,18 @@ func (p *player) nudge(g *game) {
|
|||||||
// We may have been stopped before this and had no heading
|
// We may have been stopped before this and had no heading
|
||||||
current_heading = p.Robot.MoveTo.Sub(p.Robot.Position).Normalize()
|
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()
|
new_heading := p.Robot.MoveTo.Sub(p.Robot.Position).Normalize()
|
||||||
|
|
||||||
// Is our direction change too much? Hard coding to 5 degrees/s for now
|
// Is our direction change too much? Hard coding to 5 degrees/s for now
|
||||||
angle := v.Angle(current_heading, new_heading) * v.Rad2deg
|
angle := v.Angle(current_heading, new_heading) * v.Rad2deg
|
||||||
dir := 1.0
|
dir := 1.0
|
||||||
if angle < 0 {
|
if angle < 0 {
|
||||||
dir = -1.0
|
dir = -1.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Max turn radius in this case is 100 degrees per second
|
||||||
if math.Abs(angle) > (100 * delta) {
|
if math.Abs(angle) > (100 * delta) {
|
||||||
// New heading should be a little less, take current heading and
|
// New heading should be a little less, take current heading and
|
||||||
// rotate by the max turn radius per frame.
|
// 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}
|
p.Robot.Heading = v.Vector2d{X: 0, Y: 0}
|
||||||
} else {
|
} else {
|
||||||
p.Robot.Position = p.Robot.Position.Add(move_vector)
|
p.Robot.Position = p.Robot.Position.Add(move_vector)
|
||||||
|
if new_heading.Mag() > 0 {
|
||||||
p.Robot.Heading = new_heading
|
p.Robot.Heading = new_heading
|
||||||
|
} else {
|
||||||
|
log.Printf("Zero Heading %v", new_heading)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user