+1 vote

I have in my scene two objects a rigidbody2d (player) and a kinematicbody (bullet). The bullet is created from cod (preload scene and instance). The bullet shows up correctly, detects the collision with the player and frees itself from the scene. The problem that I have is that the method onbodyenter of he player is not registering the collision.
If I add the bullet into the scene in the editor is detected by the player. The player detect other bodies (staticbodies, kinematicbodies rigidbodies that are created through the editor, not from code).
Is this the intended use or is it a bug, or am I doing something wrong. I changed the Rigidbody with a KinematicBody, the kinematic did not registered the bullet collision either).
The bullet is fired at a 0.5 second interval with a velocity of about 500 (on x), so it is not very fast and never goes through the player.
I have played with the settings from the rigidbody, but nothing helped.
thanks !

in Engine by (528 points)

1 Answer

0 votes

Body enter could be the problem.

If you want to detect collisions (rigid body has disabled contact reporting by default), use the RigidBody methods instead of body enter.
Not sure but I think that Kinematic nor static will ever "enter" a rigid on the same layer/mask pair (I could be wrong).

Also, if you want the bullet to keep moving pushing the rigid, it can't use move() because it prevents overlaps, you will have to use set_pos.

If you want the bullet to pierce the body, you may need to work with areas on that layer instead of a physicsbody (be area on the bullet or in the player or both).

You can make objects with different combinations of areas and bodies (and layers and masks) to get many levels of collisions and detections to be reported to the main node.

by (7,898 points)

body_enter is a RigidBody function, and the rigidbody has the contact monitoring function enabled (I used code and editor settings), and as I said is reporting other contacts.. I'm going to make a short project and raise the issue on github..
Good thing Godot always has other ways of doing things :) I can write the code in the bullet which detects la collision so is not a big deal in the end.

_on_body_enter is a signal, only triggered if the body is connected to it

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 webmaster@godotengine.org with your username.