Find where collision takes place

Godot Version

4.2

Question

I have 2 RigidBodies2D and i want to know where they collide.
I use GetCollidingBodies() but i just get the bodies.
Idealy I want to know if there is a way to find between which points of the polygon 2d the collision takes place.
Thanks in advance.

RigidBody2D extends the PhysicsBody2D which has the method move_and_collide. If you look at this method you can use it to test a collision, and it will return a KinematicCollision2D instance. Using this instance you can view the position using get_position() and other data about the collision that occurred between the bodies.

1 Like

Yes, with that i got the position of the collision.
Is there a way to find within which points of the collision polygon the collision takes place?

you could use a combination of the collision’s normal and remainder vectors to determine based on the original movement vector to calculate the exact point relative to the collision shape. What type of collision shape are you using to test the collision? The math will vary based on the shape you are using.

c#

 public void CheckCollision(KinematicCollision3D collision, float angle)
    {
        var staticBody = (Node)collision.GetCollider();
        var pos =  collision.GetPosition()

WHERE

                var collision = MoveAndCollide(_pw * (float)delta);
		if (collision != null)
		{
			var angle = Mathf.RadToDeg(collision.GetNormal().AngleTo(_pw));
			CheckCollision(collision, angle);
			_pw = collision.GetRemainder().Bounce(collision.GetNormal());

            }