godotengine / godotengine/godot-docs
Add details about KinematicBody2D collisions
- Dominant language
- reStructuredText
- Stars
- 5.7k
- Forks
- 3.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 25
Description
**Your Godot version:**
3.3.4
**Issue description:**
I just figured out you can't "chase" one KinematicBody2D object with another KinematicBody2D object, at less than distance A for speed B, without generating a collision every frame. This differs from other physics engines I've used, so this is probably worth mentioning somewhere. Specifically, it should be mentioned how `move_and_collide()` etc. differ from engines that move all objects and then resolve collisions (or so they seem).
Apparently, `move_and_collide()` is instantaneous. While this is a bit surprising for a physics object, it is not terribly surprising given how the function works. What is very surprising, however, is that it **always** collides with the other object's position last frame -- even if it has already been moved this frame (which can be controlled by `process_priority`).
In other words (pictures), this is what the display looks like at the moment a player is dribbling a soccer ball and collides with the ball:

As you can see, the player is 2-3 pixels away from the ball at the point of collision (Safe Margin set to 0.01 on each).
If I move the ball back to where it was last frame, however, it looks like this:

"Oh!..... now I can see what happened."
So, thinking about engine design, this makes some sense... but finding some details on it would have saved me a day of stepping through code [Why does F10 stop on comments???].
Off doc topic: Personally, I would like to see an option added to the engine to control this behavior (collide with current instead of cached locations) but I'll leave that to the engineers to mess with or not. BTW, the workaround on this one was to get creative with setting and resetting the collision layers as needed..
Just an FYI: I ported this from my prototype in Phaser's Arcade Physics. I don't know if Phaser Arcade Physics is theoretically faster than Godot KinematicBody2D (if Phaser were compiled etc.), but limiting an engine to non-rotated rectangles and circles sounds good to me for some projects (like my current one) if it means more speed.
**URL to the documentation page (if already existing):**
https://docs.godotengine.org/en/stable/tutorials/physics/using_kinematic_body_2d.html
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.