so this is the script for my path finding person mosnter thing
extends CharacterBody2D
Speed of the ghost's movement
var speed = 400
Declare the player variable
var player : CharacterBody2D = null
Called when the node is ready
func _ready():
# Get the player (Devin) node
player = get_node("../Devin") # Adjust path if needed
func _physics_process(delta):
if player == null:
print("Player reference is null. Check the path or node structure.")
return
# Get the direction to the player (Devin)
var direction = (player.global_position - global_position).normalized()
# Set velocity for movement (direction * speed)
velocity = direction * speed # Use the `velocity` property in Godot 4
# Move the Ghost towards the player (Devin)
move_and_slide()
# Check for collision with the player (Devin)
for i in range(get_slide_collision_count()):
var collision = get_slide_collision(i)
if collision.collider == player:
# Restart the game (reload the current scene)
get_tree().reload_current_scene()
return
and when the object approaches the player it stops just like in the picture above and stop moving towards the player. How do i make it so that it actually goes to the player and restarts the game when it touches it