move_and_slide fix with Safe Margin

The problem I’ve been having:

The red lines are the move_and_slide computed vectors. They go haywire when they reach the corner

The solution I’ve found is to increase the Safe Margin on the KinematicBody2D.

Set to 10. Originally set to 0.08.

With this description I think I found it:

Extra margin used for collision recovery in motion functions (see move_and_collide(), move_and_slide(), move_and_slide_with_snap()).

If the body is at least this close to another body, it will consider them to be colliding and will be pushed away before performing the actual motion.

A higher value means it’s more flexible for detecting collision, which helps with consistently detecting walls and floors.

https://docs.godotengine.org/en/stable/classes/class_kinematicbody2d.html?highlight=safe_margin#class-kinematicbody2d-property-collision-safe-margin

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.