pathfinding questions...

Post Reply
User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

pathfinding questions...

by azekill_DIABLO » Post

hello! i will be short: how to make a mob follow a path? (oh btw, how to properly store the path in an entity :D) thx!
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
burli
Member
Posts: 1643
Joined: Fri Apr 10, 2015 13:18

Re: pathfinding questions...

by burli » Post

There are two ways to follow a path. The simple one is to move from node to node. If the mob is close enough select the next node as target.

A bit more complicated is it to calculate the nearest segment and move along the path, but you need some vector calculation for this.

The problem of the first way is, that if you miss a target node, e.g. because the mob continues moving while the code lags, the mob turns around and moves back

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: pathfinding questions...

by azekill_DIABLO » Post

Can you show me a sample of code using minetest.find_path? (or your WIP pathfinding if you prefer)
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
burli
Member
Posts: 1643
Joined: Fri Apr 10, 2015 13:18

Re: pathfinding questions...

by burli » Post

I'm not at home, so I can't you show my code. But you can search for steering behaviours pathfinding.

That's what I use in my videos

hajo
Member
Posts: 606
Joined: Thu Oct 13, 2016 10:45
Location: DE
Contact:

Re: pathfinding questions...

by hajo » Post

azekill_DIABLO wrote:how to make a mob follow a path?!
You have seen smart mobs ?

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: pathfinding questions...

by azekill_DIABLO » Post

Sure, i will dig into the code.
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: pathfinding questions...

by azekill_DIABLO » Post

okay still don't get it LOL.
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

hajo
Member
Posts: 606
Joined: Thu Oct 13, 2016 10:45
Location: DE
Contact:

Re: pathfinding questions...

by hajo » Post

azekill_DIABLO wrote:how to make a mob follow a path?
How do you get/calculate that path ?
Can it change, how do you update ?
Is it just one mob, or several ?
Can they block each other, who gets to move first ?

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: pathfinding questions...

by sofar » Post

azekill_DIABLO wrote:okay still don't get it LOL.
https://github.com/sofar/entity_ai/blob ... th.lua#L86

you store the path in the entity luaobject, essentially.

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: pathfinding questions...

by azekill_DIABLO » Post

Okay for this... and then how to make him follow that?

oh and BTW, where i should define self.path? in on_activate?

EDIT: https://github.com/sofar/entity_ai/blob ... h.lua#L109
that it no, to make the mob follow? it's so complicated!
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: pathfinding questions...

by sofar » Post

azekill_DIABLO wrote:Okay for this... and then how to make him follow that?

oh and BTW, where i should define self.path? in on_activate?

EDIT: https://github.com/sofar/entity_ai/blob ... h.lua#L109
that it no, to make the mob follow? it's so complicated!
remember that entities in minetest are luaentities, and you can put any information into them - they're essentially tables that have no restrictions.

entity_ai abstracts the path finding and the path following code into the path class code you looked at. The path:step code is executed every entity on_step() callback to move the entity to the next point in the path. It all looks very complex because it is - this is the reason I developed entity_ai in the first place - nobody can really develop all the bits that are needed to make good entities. But if you make a good abstraction, people can work on the separate parts of it and make something fantastic together...

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: pathfinding questions...

by azekill_DIABLO » Post

i'm going to melt my brain with all of this. Thanks!

*coding*
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: pathfinding questions...

by azekill_DIABLO » Post

Wiow, it really helps me! thank you again!

but I have a problem i can't solve... If the returned self.path is a table of successive postitions; self.path[1] should return a pos no? i have no idea how to extract the different postition from the path... can you help me?
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: pathfinding questions...

by azekill_DIABLO » Post

*bump*
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: pathfinding questions...

by sofar » Post

azekill_DIABLO wrote:Wiow, it really helps me! thank you again!

but I have a problem i can't solve... If the returned self.path is a table of successive postitions; self.path[1] should return a pos no? i have no idea how to extract the different postition from the path... can you help me?
in entity_ai I just look at the "next" step. And once an entity is "close enough" to that step, it is removed from the table. Then the next iteration will just look at the step after that, since that is now the "next" step. Until the path is empty.

https://github.com/sofar/entity_ai/blob ... h.lua#L121

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: pathfinding questions...

by azekill_DIABLO » Post

It wasn't what i looked for, sorry, but thanks. I'm asking if it's possible to get, for example the position of the third step of the path as a table.
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: pathfinding questions...

by azekill_DIABLO » Post

Code: Select all

local nextpos = next(path)
			print(nextpos)
returns '1'. What?
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: pathfinding questions...

by sofar » Post

azekill_DIABLO wrote:

Code: Select all

local nextpos = next(path)
			print(nextpos)
returns '1'. What?
`next` returns `index, value` from the table (path).

So you should do:

nextindex, nextpos = next(path)
print(nextindex, minetest.pos_to_string(nextpos))

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: pathfinding questions...

by azekill_DIABLO » Post

oh thank you!! I was totally unuware you could do such a thing, and that why I was lost when looking at you API... I will not forget ;)
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 7 guests