Topic was automatically imported from the old Question2Answer platform.
Asked By
Nightmare
Okay so this is sorta confusing so what i want is i have an enemy that has a raycast going off the end of it, and i want it to be able to see everything but only fire if the collider is the player. Normally i would have this
onready var player = get_node("/root/World/Player")
if $RayCast2D2.is_colliding():
if $RayCast2D2.get_collider() == node:
is_attacking = true
$AnimatedSprite.play("long attack")
var fireball = FIREBALL.instance()
if $AnimatedSprite.flip_h == false:
fireball.direction *= -1
fireball.set_fireball_direction(-1)
else:
fireball.set_fireball_direction(1)
get_node("Position2D").add_child(fireball)
$Timer4.start()
and this works just fine… for the first world. it wont work in any other world how would i get it to see that without having to get the nodepath from each world??
Other methods might include assigning the object to a manager in the editor or the node broadcasting its path via some registration method or an event bus.
How would i do that because when i tried using the
all i have is a var named node and it has the get nodes command and it wont work.
I can give you a preview of what i am trying to do because it is hard to explain while writing it. I will try again if you didnt understand fully
I have an enemy scene and a player scene and a world scene. The scorpion has a raycast that sees everything but will only attack if it sees the collider as the player node in that scene. so i use a get_node function to get the player node in that scene and it works just fine but when i go to the next world it no longer works because its not in world 1 anymore its in world 2 how do i make the raycast check for the player node regardless of what scene
Nightmare | 2021-11-27 04:45
Is the player in the scene? The error would suggest not. What are you trying to do? The node you wish to find must be in the scene, or do you mean to create a player node? More information would help, yes.
spaceyjase | 2021-11-27 22:04
i hope this helps explain also the player is not in the exact same scene as the enemy