0 votes

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 .

Godot version 3.2 i think
in Engine by (17 points)

1 Answer

+1 vote
Best answer

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!

by (577 points)
selected by

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?

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.

oh ok, thank you very much.

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.