davidyu / Sonar

Networked multiplayer SHMUP-lite
http://lewenyu.com/sonar
MIT License
0 stars 0 forks source link

Fix collision detection glitches #5

Closed davidyu closed 10 years ago

davidyu commented 10 years ago

If you run into a wall, you wrap to the closest endpoint. This is most likely a bug I introduced while refactoring closestLinePoint

davidyu commented 10 years ago

It's not clear to me why, but 6be68278d053000cfb2ae8e5d02d5ec7890f8a46 fixes this.

davidyu commented 10 years ago

Resolved the tension after thinking about it a bit. This was left as an inline comment:

Think about it intuitively, like this. Suppose we wanted the scalar projection of the vector AB onto itself. We expect a value of 1.

AB . AB = AB.x * AB.x + AB.y * AB.y, or lengthsq. Now, when we normalize this scalar value, we'd intuitively want lengthsq, and not sqrtlength. This is why we divide by ab.lengthsq()