jorendorff / turtle-wars

3 stars 4 forks source link

Improved laser hit detection #4

Closed jorendorff closed 11 years ago

jorendorff commented 11 years ago

The right way to do this is:

  1. treat the laser as a line segment from the old position to the new position
  2. find the distance from that line segment to the turtle (you can use this answer which includes JS source code for that)
  3. it's a hit if that distance is less than the radius of the turtle

That way the laser speed could be huge and it would still work; you couldn't "miss" a turtle by going too fast.

jorendorff commented 11 years ago

oops, fixed it.