How to make an ai that goes to a specific point

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Evanzap
Prole
Posts: 4
Joined: Mon Jul 04, 2022 4:35 pm

How to make an ai that goes to a specific point

Post 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!
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: How to make an ai that goes to a specific point

Post 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.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
togFox
Party member
Posts: 770
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: How to make an ai that goes to a specific point

Post by togFox »

Spawn agent
Find a path
Move along path

Which bit does your question relate to?
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
Evanzap
Prole
Posts: 4
Joined: Mon Jul 04, 2022 4:35 pm

Re: How to make an ai that goes to a specific point

Post 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
User avatar
BrotSagtMist
Party member
Posts: 607
Joined: Fri Aug 06, 2021 10:30 pm

Re: How to make an ai that goes to a specific point

Post 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.
obey
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: How to make an ai that goes to a specific point

Post 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.
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: How to make an ai that goes to a specific point

Post by darkfrei »

Nice text about pathfinding and optimization:
https://factorio.com/blog/post/fff-317
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Evanzap
Prole
Posts: 4
Joined: Mon Jul 04, 2022 4:35 pm

Re: How to make an ai that goes to a specific point

Post 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
User avatar
BrotSagtMist
Party member
Posts: 607
Joined: Fri Aug 06, 2021 10:30 pm

Re: How to make an ai that goes to a specific point

Post by BrotSagtMist »

Then why are you stating to use box2d?
Anyway for tiles, i tried writing a tutorial for that a while back:
pathfinding.love
(3.28 KiB) Downloaded 144 times
obey
Evanzap
Prole
Posts: 4
Joined: Mon Jul 04, 2022 4:35 pm

Re: How to make an ai that goes to a specific point

Post 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
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 37 guests