Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | CommonDark |
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
what code have you written so far? What kind of object is the enemy?
Millard | 2020-09-08 20:33
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 _physics_process(delta):
if player == null:
return
var vec_to_player = player.global_position - global_position
vec_to_player = vec_to_player.normalized()
global_rotation = atan2(vec_to_player.y, vec_to_player.x)
move_and_collide(vec_to_player * MOVE_SPEED * 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
CommonDark | 2020-09-09 12:00