![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Kaynn Cahya |
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:
bullet.split()
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?
mirageowl | 2021-04-05 18:31
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.
archeron | 2021-04-07 06:59