I have really been trying to make the enemy follow the player for 2 weeks and is becoming, honestly, boring. This is not the ideal experience I wish to have when making my games, but there you go.
The game is top-down and there is only 4 way movement (e.g. -y, y, -x, x). One problem, is if I am diagonally from the enemy he walks diagonally. Could I use a tilemap to do this??
If you suggest using an area 2d, pls show advancements to my code which I have presented (I would also like to use a circular area2d, if possible)
EDIT: the walking is working but it is still choppy, like the enemy isn't following my character when I'm in range and it runs by itself with my being in range.
It is very likely that I've seen the tutorials if you present them. I have seen the gdscript one, as he's one of the first people I go to.
func _physics_process(delta):
velocity = move_and_slide(velocity)
if BEntered == player:
if player.position.y < position.y:
velocity.y = -speed
elif player.position.y > position.y:
velocity.y = speed
else:
velocity.y = 0
if LEntered == player:
if player.position.x < position.x:
velocity.x = -speed
elif player.position.x > position.x:
velocity.x = speed
else:
velocity.x = 0
if nterd == player:
if player.position.x < position.x:
velocity.x = -speed
elif player.position.x > position.x:
velocity.x = speed
if player.position.y < position.y:
velocity.y = -speed
elif player.position.y > position.y:
velocity.y = speed
else:
velocity = 0
func _on_DetectPlayer_body_entered(body):
BEntered = player
func _on_DetectPlayer_body_exited(body):
BEntered = null
func _on_DetectPlayer3_body_entered(body):
LEntered = player
func _on_DetectPlayer3_body_exited(body):
LEntered = null
func _on_Circle_body_entered(body):
nterd = player