This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello everyone!

I am trying to get collision on a RigidBody2D.
However it keeps returning <Array([])>
I already turned on contact monitor and set Contacts Reported to 1

it still returns <Array([])> however.

What am i doing wrong?

i am using godot3.0.6

in Engine by (33 points)

1 Answer

0 votes

If you read the documentation for getcollidingbodies() function, you'll realize it's not the best suited function to use to detect collisions for a RigidBody2D, and that it is working as intended by returning an Array of colliding bodies. I'd strongly advise you to use either RigidBody2D's bodyentered and bodyexited signals or directional raycasting, e.g. having multiple RayCast2D nodes, and checking their collisions each physics tick. Or additionally use Area2D that has a slightly bigger cillision than your RigidBody2D and it's bodyentered and bodyexited signals. Also set-up physics layers, so you can use collision layers and collision masks to avoid checking for collisions where it's not needed.

It's hard to give you the right answer without really knowing what is your intention and what kind of collision are you checking for. You can read up more about your use case here RigidBody2D documentation.

by (129 points)
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 Frequently asked questions and 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 [email protected] with your username.