Topic was automatically imported from the old Question2Answer platform.
Asked By
Explosive Pineapple
hello, i want to make an enemy that can shoot bullets at my player. however i have one problem. how do i get the location of the player to the bullets because they dont know where to go. In better words, how do i get the location of a sprite in another scene because the bullet and the player are in another scene. I am new to godot so i dont know if there is any other way to do this. thank you .
If the enemy and the player are together in a scene you could just do:
var player = get_parent().get_node("player")
target = player.global_position
Of course, make sure when you use the get_node(), you pass the actual name of your player scene. I hope that helps!
thank you this helped but for something else that i was having a problem with. the issue is, they are in 2 different scenes so do i put the path to the scene there instead?
Explosive Pineapple | 2021-01-26 05:24
If you have a world scene with backgrounds and such, just put them both in that scene. If not, you could just make a scene with a Node2D and put them both in that. If you can’t have them in the same scene, you could make a global script with a singleton for player. Just look up on youtube, Godot singletons, and there are some good videos. A singleton basically would make the players properties available to all nodes.