0 votes

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 health
changed
export (int) var MOVESPEED
export(int) var detect
radius
export(int) var damage = 10
var med = preload("res://medkit.tscn")
var health

var player = null

func ready():
set
process(false)
addtogroup("zombies")
health = maxhealth
emit
signal("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

in Engine by (77 points)
edited by

Are you using a tilemap? if so you may want to look into the Navigation2D node.

Check out this video on tilemaps and nav2d and you should be ready to make it happen:

https://www.youtube.com/watch?v=0fPOt0Jw52s

thank that will be useful!!!

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.