0 votes

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():
    queue_free()
    pass # Replace with function body.





func _on_Obstacle_body_entered(body):
    print("I AM COLLIDING")
    pass # Replace with function body.
Godot version v3.4.4.stable.official
in Engine by (12 points)

1 Answer

+1 vote

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():
    connect("body_entered",self,"_on_body_entered")

func _on_body_entered(body):
    print("collided")
    queue_free()

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

extends KinematicBody

func _physics_process(delta):
    if Input.is_action_pressed("ui_right"):
        move_and_slide(Vector3(1.0,0.0,0.0))

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!

by (74 points)

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! :)

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.