Another bug popped: The bot teleported to the outside of the room after collision sometimes.
This time, the culprit was floating-point numbers. Even though I used round numbers for speed constants, I used lerp to simulate acceleration and deceleration.
So for example, if the bot’s x is touching a wall at 40, in the next step, it might be changed to 39.9, which is already inside the wall. The collision detection code might catch it while checking on the y collision and decide the bot should be on top of the wall. Hence the teleport.
Lesson learned:
- Round the numbers before assigning them to positions.
- Do all speed manipulations before applying it to positions.
Leave a comment