How to stop movement completely when collision is happening?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Skydome

I have two kinematic bodies, By pressing the D key I move one to the right. Collision happens as you’d expect. But if I keep pressing D while colliding the body slowly starts moving either upwards or downwards until it’s able to slide past the colliding object. Because in my game the two kinematic bodies are both human characters this looks really odd.

I tried to sort of circumvent this by adding an area2d and signal it so that velocity and speed becomes 0 if the area2d’s collide. And this works for the first time. But the thing is that Area2d doesn’t continuously detect collision. It just sends the signal once when collision happens for the first time. If the two bodies are continuously colliding it doesn’t keep sending the signal.

I tried with rigid body instead of area2d and that didn’t detect collision at all.

I’m going to try static body now. If there are any suggestions that can help me please let me know.

:bust_in_silhouette: Reply From: Lopy

You can try using move_and_collide() instead of move_and_slide(), or a move_and_slide() with max_slides at 0.
To detect a continuous collision, you can use Areas. They have get_overlapping_bodies() and get_overlapping_areas() functions.

I’m already using move_and_collide(). move_and_collide() makes collision happen continuousuly yes but if I am moving to the right and collision is happening then the body slowly moves either downward or upward from the velocity*speed exerted on it.

Right now I have decided that an oh excuse me animation will happen when there’s a collision. The character will take a step back. This happens in Skyrim too so I think it will work.

What do you mean in the second line? Use Areas? Like Area2D? But that doesn’t detect continuous collision. It only detects when the body enters, it send the signal but if the body is still colliding it doesn’t keep sending the signal.

Skydome | 2021-01-01 02:07

I got another idea. Use a bool when I get signal of entering. Enable the bool to stop movement. But when there’s signal of exiting bool is false. Will try this as well.

Skydome | 2021-01-01 02:15

1 Like