I can't get body_entered to activate

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Aneksuz

I am quite new to Godot still and pretty new to GameDev overall (especially in 3D)

I have a spawner in my world scene which spawns obstacles that I want to get deleted when they hit the player. (3D BTW)

The player is a KinematicBody and the Obstacles are RigidBodies. I try to use the signal body_entered to trigger and event through a signal but it never activates.

Contact Monitor is on, Contacts Reported is set to 1000 just to be sure, I have a collisionshape as a child of the RigidBody, I’ve set and double checked collision layers and they should be fine (as if I enable collision on the mesh of an obstacle it works fine).

Not really sure what to try next or how to approach this

Code for the collision below:

extends RigidBody

# Declare member variables here. Examples:
# var a = 2
# var b = "text"
export (int) var speed;

# Called when the node enters the scene tree for the first time.
func _ready():
	connect("body_entered", self, "_on_Obstacle_body_entered")
	apply_impulse(transform.basis.z, transform.basis.z * speed)

# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass

#func _physics_process(delta):

func _on_Timer_timeout():
	pass # Replace with function body.

func _on_Obstacle_body_entered(body):
	print("I AM COLLIDING")
	pass # Replace with function body.
:bust_in_silhouette: Reply From: RaebaldKashban

I was able to get this to work with the following code:

RigidBody node hierarchy is as follows: RigidBody > CollisionShape, CSGSphere.
RigidBody properties: Contact Monitor = On, Contacts Reported = 1000
RigidBody code:

extends RigidBody

func _ready():

func _on_body_entered(body):

KinematicBody node hierarchy: Kinematic Body > CollisionShape, CSGBox
KinematicBody code (simple movement):

extends KinematicBody

func _physics_process(delta):
	if Input.is_action_pressed("ui_right"):

Here’s what I see on startup:
3D Collision Detection

Here’s what I see after the cube collides with the sphere:
3D Collision Result

What I have for the RigidBody seems consistent with the way your RigidBody is set up, so I’m wondering if there’s an issue with your KinematicBody? Hopefully this is somewhat helpful. Good luck!

Thanks a lot for answering my question. I don’t know what have gotten messed up with my Obstacle but it looks like I will have to rebuild it from scratch cause when I make a new RigidBody it works fine. No idea what might have caused this. Thankfully it won’t take long at all to redo the Obstacle scene.

I should have taken the time to redo it myself before asking, however thanks for taking the time to respond! Much appreciated! :slight_smile:

Aneksuz | 2022-04-09 20:43