0 votes

I want to get a component from an object through collision.

What I have done so far:

var collision = move_and_collide(velocity)
if collision:
    velocity = velocity.slide(collision.normal)

    # Stuck here, how do I get the Bullet Component/Script from the collision node.
    var bullet = collision.collider.get("Bullet")

    if bullet != null:
Godot version v3.2.3
in Engine by (12 points)

collision.collider is the node that you collided with. If Bullet is the name of a child node of the node that you collide with your code should work. If Bullet is the node that you collided with then you don't need .get("Bullet") . Check here if my wording was confusing.

I'm not sure what you are trying with split since nodes don't have a method named split. Are you perhaps trying to access a variable inside the node first, which happens to be a collection so you can split it?

You need to provide the relevant parts of the two node trees involved in the collision to get a meaningful answer. We can't answer your question if we don't know anything about where your "Bullet" node resides relative to the nodes involved in the collision.

Please log in or register to answer this question.

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.