Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | CatboyCodes |
Hi, I’m having a problem with my enemies, when there are 2 enemies, they both chase each other instead of the player.
My code for the enemies:
extends KinematicBody2D
var run_speed = 25
var velocity = Vector2.ZERO
var player = null
func _physics_process(delta):
velocity = Vector2.ZERO
if player:
velocity = position.direction_to(player.position) * run_speed
velocity = move_and_slide(velocity)
func _on_Alert_body_entered(body):
player = body
func _on_Alert_body_exited(body):
player = null