Page 1 of 2
How to make an ai that goes to a specific point
Posted: Mon Jul 04, 2022 4:54 pm
by Evanzap
Hello! How would I go about making a function that spawns in an ai that can path find and then take that route to the location. The collision method I use is box2d. If there is a way that i could do this without messing with node things that would be great!
Re: How to make an ai that goes to a specific point
Posted: Tue Jul 05, 2022 5:36 am
by darkfrei
Simple way: don't do that, for example don't check the collision or don't use the pathfinding, just wait until the player will be on the straight line to this agent.
For other situations you can use the astar
https://en.wikipedia.org/wiki/A*_search_algorithm or any other the pathfinding solutions.
Re: How to make an ai that goes to a specific point
Posted: Tue Jul 05, 2022 5:44 am
by togFox
Spawn agent
Find a path
Move along path
Which bit does your question relate to?
Re: How to make an ai that goes to a specific point
Posted: Tue Jul 05, 2022 5:07 pm
by Evanzap
togFox wrote: ↑Tue Jul 05, 2022 5:44 am
Spawn agent
Find a path
Move along path
Which bit does your question relate to?
I guess find a path and move along path
Re: How to make an ai that goes to a specific point
Posted: Tue Jul 05, 2022 5:37 pm
by BrotSagtMist
The problem is that box2d isnt really nice for pathfinding.
If you use tiles or a hexagon map pathfinding is just a couple of easy lines. That is because collision is easy there too, we just have to touch tiles till we find the target and then traverse back.
But on free movable objects you can not go around and touch every way possible, that would be an infinitive work.
I other words, that is a complicated task. There are however solutions on this forum for it.
Re: How to make an ai that goes to a specific point
Posted: Tue Jul 05, 2022 7:16 pm
by MrFariator
You say you want to accomplish this without nodes, but as BrotSagtMist says, pathfinding is easier to do on those nodes. If you can split the map so that it forms a grid, you can use that grid as the basis for the path finding over larger distances. Once the actor is close enough to its goal, you can ignore the grid, and use some other methods, if so desired.
In the end, how to approach this will ultimately depend on how your maps are structured.
Re: How to make an ai that goes to a specific point
Posted: Wed Jul 06, 2022 7:09 am
by darkfrei
Nice text about pathfinding and optimization:
https://factorio.com/blog/post/fff-317
Re: How to make an ai that goes to a specific point
Posted: Wed Jul 06, 2022 11:20 pm
by Evanzap
BrotSagtMist wrote: ↑Tue Jul 05, 2022 5:37 pm
The problem is that box2d isnt really nice for pathfinding.
If you use tiles or a hexagon map pathfinding is just a couple of easy lines. That is because collision is easy there too, we just have to touch tiles till we find the target and then traverse back.
But on free movable objects you can not go around and touch every way possible, that would be an infinitive work.
I other words, that is a complicated task. There are however solutions on this forum for it.
I use tiles, there are no curves or anything
Re: How to make an ai that goes to a specific point
Posted: Wed Jul 06, 2022 11:35 pm
by BrotSagtMist
Then why are you stating to use box2d?
Anyway for tiles, i tried writing a tutorial for that a while back:
Re: How to make an ai that goes to a specific point
Posted: Thu Jul 07, 2022 12:12 am
by Evanzap
BrotSagtMist wrote: ↑Wed Jul 06, 2022 11:35 pm
Then why are you stating to use box2d?
Anyway for tiles, i tried writing a tutorial for that a while back:pathfinding.love
i'm using sti and a script to convert objects into colliders, it's quick and easy