My enemy wont move

Godot Version

4.5

Question

It wont move and it did have an error but i removed the script and then made an new script but it still had the same code so i pressed play and it worked but didnt move so idk what do

if it helps the error was Invalid access to property or key “global_position” on a base object of type “null instance”

and the video im using is Your first 3D game with Godot 4 | GDQuest Library

and my script is

extends RigidBody3D

var speed = 3.0

@onready var player = get_node("/root/Game/Player")


func _physics_process(_delta):
	var direction = global_position.direction_to(player.global_position)
	direction.y = 0.0
	linear_velocity = direction * speed

Your player may not exist when this enemy is ready, you might be able to re-order the scene tree or use a @export to assign the player reference instead.

ok thanks, i look at your other post but it didn’t help

Might I inquire why you are using a rigid body? Of you use a character body then you can do the same thing with velocity rather than linear velocity and then you just call move_and_slide(). That’s just a thing that makes it easier to control, I don’t think it’d fix the issue though.

because thats what the tutorial said to do

a new error has happened when make i it @export instead it comes up with Invalid access to property or key ‘global_position’ on a base object of type ‘null instance’, so i tried to re-order my scene tree and that didnt work

You can try to define player in physics_process() because some ready functions happen before others. Eg

var player

func physics_process():
    player = whatever

it follows me but it rolls, idk what to do

dont matter i fixed it