Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Extenos |
So, I’m trying to make an insanely basic first game in Godot so I can learn the ropes. In it, there are going to be enemies flinging themselves towards the player so the player has to dodge them. To do this, I tried getting the player’s position using the get_position()
function and putting it into a variable that the enemy can later access using the get_node().get()
function. However, I think that the fact that I am instancing a scene to spawn the enemy has something to do with the game not spawning anything when it’s trying to.
Here’s a video showing everything I feel like is necessary to fixing this.
Here’s the tutorial with the code I modified to make the non-functional spawning system.
I couldn’t include the code and errors directly in the post due to length issues, but if you need any extra info to help me, just ask.
Add Enemy script
onready var player = get_parent().get_node(“player”)
var pos
func _ready():
pos = player.global_position
print(pos)
pass
ramazan | 2022-08-06 19:34
Sadly it didn’t work and I got the error “The method “getparent” isn’t declared in the current class.” The game won’t boot anymore.
Extenos | 2022-08-06 20:24
The message was screwed by formatting, ramazan meant
onready var player = get_parent().get_node("player")
var pos
func _ready():
pos = player.global_position
print(pos)
pass
ynot01 | 2022-08-06 21:22
try
var main
var player
var pos
func _ready():
main = get_tree().current_scene
player = main.get_node("Player")
pos = player.global_position
print(pos)
pass
ramazan | 2022-08-07 07:32
These both just give "Invalid get index 'global_position' (On base: 'null instance')
tbh i think im too dumb for this
Extenos | 2022-08-07 14:42
what is the node type ? Player
Aree2d , kinematicbody, sprite or etc…
ramazan | 2022-08-07 21:05