+1 vote

Hi i need help to set pathfinding to enemy ai in my top down shooter game because ai for the moment is just stupid and walks into walls to catch me.
By states i mean patrolling and attack for example patrolling state they will patrol area or dont move and when they see player they follow him with path finding

in Engine by (19 points)
edited by

what code have you written so far? What kind of object is the enemy?

Here's code of enemy:
P.S also my game will have multiple levels

extends KinematicBody2D

const MOVE_SPEED = 200

onready var raycast = $RayCast2D

var player = null

func ready():
add
to_group("zombies")

func physicsprocess(delta):
if player == null:
return
var vectoplayer = player.globalposition - globalposition
vectoplayer = vectoplayer.normalized()
globalrotation = atan2(vectoplayer.y, vectoplayer.x)
move
andcollide(vectoplayer * MOVESPEED * delta)

if raycast.is_colliding():
    var coll = raycast.get_collider()
    if coll.name == "Player1":
        coll.kill()

func kill():
queue_free()

func set_player(p):
player = p

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.