0 votes

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.

in Engine by (97 points)

1 Answer

+1 vote

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.

by (2,092 points)
edited by

I'm already using moveandcollide(). moveandcollide() 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.

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories