AI enemy following

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Themaker482
:warning: Old Version Published before Godot 3 was released.

Hi, I know this can be hard but I need help with AI, the thing is that I want the Second object"enemy" follow the first one then the second is visible into screen, Can anybody give me some ideas? The enemy doesnt have to avoid obstacles so I think that is a little easier but I dont know where should I begin… The game is 2d

:bust_in_silhouette: Reply From: batmanasb

Look up the GameFromScratch tutorial on Navigation, or the demo on NavPoly in the demo folder. I think that’s what you want for path finding. Also for LOS, you may want to look into the RayCast node or other collision nodes for that. If you are using tiles (TileMap), here’s a cool demo for adding Navigation into tiles. Link to demo Sorry for the lack of detail, I’m in Ludum Dare so i’m stressed and busy :frowning: :slight_smile:

Thanks but what iam looking fot is a way to make a enemy follow the character in a 2d platformer something that helps to change the direction of the enemy when it see the character… Something like sight range

Themaker482 | 2016-04-17 18:53

Oh… well for side scrolls I usually see game devs using 2 ray cast nodes, one going the direction the player is facing (left or right), and one going 45 degrees down from where the first one is. Not 100% how that works, but I’m guessing it somehow detects the edges of platforms. But yeah, that’s all I got, good luck.

batmanasb | 2016-04-17 21:00

Yes, something like that is whht i was looking for but, i am stuck about how to do it if you have some ideas I would like your help

Themaker482 | 2016-04-18 14:21

Hi I’m late for the party but it didn’t look like you got stuff resolved. Stumbled on this looking for some obstacle avoiding tips funny enough…
But here is what I’ve done (simple but works for now), for a node following another node, on a 2d tilemap:
func whatever_move_follow():

if my_position.distance_to(my_targets_pos) > when_close_enough_for_chase_to_start
if my_target_pos.y > my_pos.y:
my_pos.y += my_movementspeed (if grid, then grid size or number of grids * size)
elif y. < y
elif x > x
elif x < x

get_node(me).move_to(my_new_pos)

Hope it helps someone stumbling upon this :slight_smile:

Dadango | 2016-11-25 11:10