Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | RobertTeam |
My code worked perfectly and something happened, now, I don’t know why, the player node returns null and all stop working.
extends KinematicBody2D
var motion = Vector2()
func _ready():
pass
func _physics_process(delta):
var player = get_parent().get_node("player")
position += (player.position - position)/50
look_at(player.position)
motion = move_and_collide(motion)
First of all calling var player = get_parent().get_node("player")
in every physics frame is wrong. It’s enough to do this once in _ready()
.
Second, make sure your composed tree hierarchy is matching your query, use print_tree_pretty()
to see.
sash-rc | 2021-08-20 07:35