Please use ``` at the beginning and end of your code:
@export var Entity_health = 5
@export var unit_alignment : Alignment
@export var speed = 100
@export var player = (“res://Scenes/PLayer.gd”)
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting(“physics/3d/default_gravity”)
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
enum Alignment {ALLY, NEUTRAL, ENEMY}
func _ready():
if unit_alignment == Alignment.ALLY:
print(“I will Protect you”)
func _process(delta):
if player.velocity.x or player.velocity.z != 0:
player_position()
follow_player()
func follow_player():
position += (player.position - position)/ speed
func player_position():
print(player.position)
Well, that’s probably how it’s fixed (load added on line 6):
@export var Entity_health = 5
@export var unit_alignment : Alignment
@export var speed = 100
@export var player = load(“res://Scenes/PLayer.gd”)
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting(“physics/3d/default_gravity”)
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
enum Alignment {ALLY, NEUTRAL, ENEMY}
func _ready():
if unit_alignment == Alignment.ALLY:
print(“I will Protect you”)
func _process(delta):
if player.velocity.x or player.velocity.z != 0:
player_position()
follow_player()
func follow_player():
position += (player.position - position)/ speed
func player_position():
print(player.position)
For sure that line is the problem and yours is one possible solution (We don’t have enough info to be sure).
Its pretty rare that one loads a player script rather than a scene.
Usually a player object is CharacterBody2D + sprite + camera + hitbox +etc.
It may be he wants to load the scene:
@export var player_scene = load(“res://Scenes/Player.tscn”)
#and then somewhere that scene would need to be instantiated.
var player = player_scene.instantiate()
But based on the fact that it is an export and some of the code further on, it could be that he just wants to drag the node into the script in which case it would be @export var player = $Player
im very new and teaching myself of i may be doing things very inefficiently. if thwir is a better way lmk. im trying to have the mob follow the player when they move and this is a slime
Thanks for showing a little of the scene tree. As with all exported variables you will need to set a value for it in the Inspector. Select your Slime node and “Assign…” the player property there.