# Pathfinding is weird - any alternatives?

Discussion and feedback on Construct 2

### » Fri Apr 03, 2015 9:55 pm

R0J0hound wrote:The player doesn't utilize the solid behavior, it's only used for the line of sight.
It could be re-worked to utilize astar so the shortest distance is used every time, but it would have to be astar done from scratch, since it wouldn't be grid based.

If smaller objects are passed through you could roll your own LOS with events with that in mind, or probably more appropriate implement some kind of collision response to push objects out of each other. Avoiding moving objects can be done by looking at where the objects will be a little in the future and if they are colliding adjust the current angle of motion so it won't.

Hmm, I have no idea how "looking in to the future" could be done. :/
Maybe something simpler: how would you go about making characters not bump in to each other with just pathfinding? Also any suggestions how to keep formation when possible?
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
93
S
30
G
22
Posts: 1,987
Reputation: 20,203

### » Sat Apr 04, 2015 9:59 pm

At any given moment a object has a position (x,y) and a velocity (vx,vy). Using a formula like rate*time=distance, you can guess what an object's position in the future will be: (x+vx*t, y+vy*t), where t is the number of seconds in the future. If the object's velocity does not change then the guess will be 100% correct.
So checking in the future just means to move the objects to where they will be, check for overlaps, and then move them back.

For formations each object has it's own goal, which is pretty straightforward.

Collision response is what will allow units to not walk over each other or not walk over the walls.
For units this is done by finding the distance between each pair of units and just move each away from each other if they are two close.
For units against walls you find the distance to each side of the wall and use the closest side to push away from. This distance calculation is the distance from a line to a point, which is different from the distance from a point to a point.

https://dl.dropboxusercontent.com/u/542 ... find2.capx
B
95
S
34
G
128
Posts: 5,497
Reputation: 81,682

### » Sat Apr 04, 2015 10:08 pm

Tank on collision with Tank, Tank pick farthest from target x,y set speed to 0, system wait 1 second, Tank set speed to 100
Bumper cars... sorta
B
173
S
50
G
195
Posts: 8,578
Reputation: 121,892

### » Sat Apr 04, 2015 10:15 pm

R0J0hound wrote:At any given moment a object has a position (x,y) and a velocity (vx,vy). Using a formula like rate*time=distance, you can guess what an object's position in the future will be: (x+vx*t, y+vy*t), where t is the number of seconds in the future. If the object's velocity does not change then the guess will be 100% correct.
So checking in the future just means to move the objects to where they will be, check for overlaps, and then move them back.

For formations each object has it's own goal, which is pretty straightforward.

Collision response is what will allow units to not walk over each other or not walk over the walls.
For units this is done by finding the distance between each pair of units and just move each away from each other if they are two close.
For units against walls you find the distance to each side of the wall and use the closest side to push away from. This distance calculation is the distance from a line to a point, which is different from the distance from a point to a point.

https://dl.dropboxusercontent.com/u/542 ... find2.capx

Thank you so much for all your help. I ultimately decided I will go with pathfinding. Since setting rotation to very high number got rid of that annoying delay, I wander if your technique of units not stepping in to each other would work with pathfinding too?
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
93
S
30
G
22
Posts: 1,987
Reputation: 20,203

### » Sun Apr 05, 2015 6:28 pm

It probably can, since it just corrects the object's positions when they do overlap.
B
95
S
34
G
128
Posts: 5,497
Reputation: 81,682

Previous