+5 votes
in Engine by (20 points)
For collisions detection usually body_enter signals can be used, but can you elaborate little more about what you trying to do?

2 Answers

+10 votes
Best answer

I'd recommend going through the physics tutorial here.

This depends a lot on what you're trying to do. There are three main physics body types in Godot: KinematicBody, RigidBody and StaticBody. These are implemented as nodes. Further, they need a Collision object as a direct child node to define the shape of the physics bodies (CollisionPollygon2D in your case).

Now, collision reporting can be very expensive so generally speaking, RigidBody and StaticBody physics controllers do not report collisions. You can change this by increasing the number of contacts reported in the properties of your StaticBody or RigidBody node.

You can find a handy chart indicating who has access to what information in a collision here.

Here's the documentation for RigidBody2D, KinematicBody2D and StaticBody2D.

The more important functions/methods you're going to use for getting collision information reported to KinematicBody2D are as follows:

The more important functions/methods you're going to use for getting collision information reported to RigidBody2D are as follows:

As for getting information reported to StaticBody2D, here's a rule of thumb: Don't.

by (68 points)
selected by
I am currently trying to detect collision in a RigidBody2D , but it is divided into two parts, the bottom and the top , I need to detect which of these parts occurred the collision.  I already detected a collision using the body_enter signal , but it seems that does not help me with the condition cited above
0 votes

I'm late to this thread but i wanted to show this loop I use to detect if a collision happened and then execute orders based on the result.

for i in get_slide_count():
    var collision = get_slide_collision(i)
    if i>0:
        #Do your action here

getslidecollision Should be called after moveandslide(),it returns an Integer and will return "0" if no collision occurred.

Hope this helps someone!

by (14 points)

Hi. I've tried but not work. Can you help me?

My code:

func physicsprocess(delta):
for i in getslidecount():
var collision = getslidecollision(i)


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.