Page 1 of 1

How to path-find in a non-tiled world?

Posted: Sat Feb 13, 2021 12:02 am
by togFox
I have a top down 2D sports field with players running about in a pixel like way - like the whole Cartesian x/y plane is used. They don't follow tiles.

The soccer player (AI) needs to get from his/her half to the opposing goal by finding a path that best avoids the opposing team. All the libraries I've seen use a tile map and go from there.

In the absence of other techniques, I'm thinking of virtually dividing the playing field into tiles where a tile with an opposing player being a 'wall' that needs to be avoided. I can adjust and tune the size of the virtual tiles through experimenting or even in real time depending on how/where the players move. I can refresh the virtual map once per dt (or whatever).

Another option is something I'd need to research where some sort of 'density' analysis determines where there are more players ( to avoid) or less players (more viable).

Where should I start?

Re: How to path-find in a non-tiled world?

Posted: Sat Feb 13, 2021 3:40 pm
by Xii
If the number of entities isn't too high, what you can do is consider the distances and directions (vectors, essentially) towards each and every other entity.

Begin with a vector pointing straight to the goal, or something. Then, loop over all opponents. Subtract from the initial vector the vector towards each opponent, weighted by the inverse square of the distance to said opponent. Then have the entity move towards the final resulting vector. This creates avoidance behavior in real-time.

Re: How to path-find in a non-tiled world?

Posted: Sat Feb 13, 2021 8:05 pm
by dusoft
A* / A star? Pixels are basically tiles or tiles are represented in the same way as pixels - by their X,Y position.

Pixels/tiles taken by opposing players are basically just blockers/walls.

Re: How to path-find in a non-tiled world?

Posted: Sun Feb 14, 2021 12:22 am
by togFox
oh - that vector method is not something I've seen before and this project has made me very comfortable with vectors.

The A* method would give a poor result because my 'grid' is 100 pixels by 53 pixels. That's 5300 pixels with only 11 pixels occupied. The vector method would demonstrate avoidance in a way that A* would not.

Thanks both. More learning to do.