Hi actually, I try to improve my enemy AI of my 2D project but the promblem it I can't make the enemy detect the wall and find a other way to go to the current position of the player just like this.
LEGEND:
square:wall
circle:enemy
diamond:player
I am thinking to do it whit Raycast2D but I don't think it gonna work or whit ASart but I don't not how to use it (~_~;).Thank for helping me it really appreciate.
here my code of my enemy.
extends KinematicBody2D
export (int) var maxhealth = 75
signal healthchanged
export (int) var MOVESPEED
export(int) var detectradius
export(int) var damage = 10
var med = preload("res://medkit.tscn")
var health
var player = null
func ready():
setprocess(false)
addtogroup("zombies")
health = maxhealth
emitsignal("healthchanged", health * 75/maxhealth)
func physicsprocess(delta):
if player == null:
$Node2D2/AnimatedSprite.play("idle")
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)
$Node2D2/AnimatedSprite.play("walk")
func kill():
var m = med.instance()
getparent().addchild(m)
m.position = position
queue_free()
func take_oof(damage):
health-=damage
emit_signal("health_changed", health * 75/max_health)
if health <= 0:
kill()
func onvisibilitybodyentered(body):
if body.name == "Player":
player=body
func onVisibilityNotifier2Dscreenexited():
player = null