My enemy is not moving in my top down game I don't know why I just started a tutorial on how to do it and I don't know if this is something that I am missing please help
extends CharacterBody2D
@export var speed: float = 120.0
var player: Node2D
var chasing := false
func _physics_process(delta):
print("CHASE =", chasing, "VEL =", velocity) # debug print
if chasing and player:
var dir = (player.position - position)
print("DIR =", dir)
if dir.length() > 2:
velocity = dir.normalized() * speed
else:
velocity = Vector2.ZERO
else:
velocity = Vector2.ZERO
move_and_slide()
func _on_detection_area_body_entered(body):
print("ENTER:", body)
chasing = true
player = body
func _on_detection_area_body_exited(body):
print("EXIT:", body)
if body == player:
chasing = false
player = null
You should be able to see prints in your web console, usually F12 will open this but you may have to click around to prevent Godot from stealing this input.
I’m guessing you mean on this line of the sample?
You would have to add a class_name Player on your player script for this to function as you’d like. If you don’t want a class_name then you could check against the body’s name
It seems like you’ve put the condition on the body exited function, not the body entered.
The slime attaching to the player’s head is likely because the CharacterBody2D believes the player is a moving platform, since this is a top-down game you should set all of your CharacterBody2Ds to motion mode “Floating” which does not take “moving platforms” below them into account, and every collision shape is treated as a wall instead of a floor/wall/ceiling.