I am referring to this Navigation2D Tutorial .
Although I have got my enemy character to chase the Player when it is in sight but I want the Enemy AI to complete its last 2D path generated and then stop whenever my player hides behind a wall or something.
This is the code for Generating The Path for the Enemy AI to follow :
if levelNav != null and player != null:
path = levelNav.get_simple_path(global_position, player.global_position, false)
line2d.points = path
This is the code for the Enemy AI to move towards the player :
if path.size() == 1:
velocity = global_position.direction_to(path) * speed
elif path.size() > 1:
velocity= global_position.direction_to(path) * speed
if global_position == path:
And this is how I call them in my
- Player detect is nothing but a function to check if the raycast from the Enemy AI is colliding with the player or a wall
player_spotted == false no more path is generated (which is what I want) but in the code where Enemy move towards the player the line of code
if global_position == path never gets executed and the enemy AI keeps twitching at a point specified in the path array
This is what it looks like :
Any help is appreciated,
Thank you for your time.