Physics Objects with Real-Time Pathfinding

Hello all,

I just have a general question about the best way to implement a pathfinding system in Corona that can support live physics objects.

Here is some basic information to help you understand what I am trying to accomplish:

I am working on a real-time rogue-like game with some friends.  The pathing is all worked out using Jumper.  There are no issues with creating a path, or following the path using transitions.  My issue lies in creating a system that allows physics objects to follow the path.  There are wall tiles, projectiles, and player physics interactions that need to be handled by the object following the path, so I believe transitions are an incorrect way of approaching the problem (however, I have tried to use transitions and then cancel once it runs into something, but that seems to spawn way more issues than it fixes).  

After deciding that transitions were no good, I moved to a full linear-velocity type approach.  I thought that I would be able to simply check the distance of the physics object to the next path-node every frame, then progress to the next node when the object was close enough to the path-node. However, this became a problem because checking distance every frame produced highly variable results.  The faster the object would be moving, the more imprecise the distance checks (I hope I am explaining this problem correctly).

My problem is how to detect when the object is ready to follow the next node.  My next idea would be to place a little invisible physics pellet in the path-node, then simply update when it runs into it, but I’m not sure if that is too complicated of a solution…

Any suggestions of a simpler solution? Something obvious I am not thinking of?

Thanks! 

Parker

In my Chasy Maze game (https://itunes.apple.com/us/app/chasy-maze/id1139444245?mt=8) I have the puffer fish chasing the diver using Jumper. The fish have a dynamic physics body and I’m using transition.to to move them from the current node in the path to the next. If there’s a collision between the puffer fish and the diver I just cancel that transition. I haven’t had any problems relating to that.

Your idea of using “node triggers” is interesting, but does seem a little over-engineered. But if it works… :slight_smile:

 Jay

PS - The fish’s path is recalculated every time they reach the next node, so I don’t have to worry about cancelling the transition due to a new path – just collisions.

Thanks Jay,

A large issue arises when the object runs into a wall.  Since the object is up against a wall, it instantly cancels any transition I try to start.  I’m sure I could make some kind of fix to prevent this problem, but it just seems like I am making it much more complicated than it needs to be.

Yeah, mine’s different because the fish aren’t being directly controlled like my player – and he’s a physics object moved with physics calls.

If you are using pathfinding, how can the object run into a wall? A wall tile should be marked as not walkable so your path should never hit it. Is the problem that the player’s bounding box can hit a wall even when he’s in the grid cell next to a wall?

Maybe someone will have bright idea we can both learn from. I’m just getting ready to play with a tiled dungeon so I’ll be doing similar things.

 Jay

If the physics object is hit by the player, or hit with a projectile, it sometimes ends up running into a wall. It cant walk on those tiles, but its not inside of the unwalkable tile, just close enough to instantly cancel the transition away from the wall… Its a weird collision call.

I want to stay away from transitions if possible.

With the disclaimer that I’m pretty new to game development, I’m currently working on a prototype with an object following another (moving) object through a maze.

The chaser object is dynamic, moved with transitions. As said above, there shouldn’t be accidental bumps into walls. There are (planned) collisions with other objects and I just cancel the transition when that happens. Every half a second the path gets recalculated so the object starts a new transition by itself. Works quite well so far.

If you want to entirely avoid collision with certain types of walls/projectiles, you can use collision filtering (masks). Or temporarily remove the physical body of the transitioned object until the collision is resolved in some other (non-physical) way.

EDIT: Noticed the new reply after posting mine… Not sure why moving away from the path would cause the object to break the transition? Does it get stuck into the wall?

No, it doesn’t get stuck or anything.  A simple velocity change would allow it to move away from the wall. The issue is that I have the transition cancel when it collides with a wall, so when it tried to start transitioning again it instantly cancel the transition.

Transitions are very easy to implement and use normally, but I need to also implement a seeking state that frequently updates linear velocity towards the player to achieve a fluid ‘seeking’ curve.  I do not want to be using two different systems to control my AI (transitions and linear velocity).

If you’re only getting pushed against the wall, but moving parallel to or away from it, it doesn’t seem like you need to cancel. If the dot product of your direction and the hit normal isn’t positive, that would be the case, and you could just keep the transition alive.

Similarly for snagging corners and such, you could use “whiskers” on your object (via raycasts, for example) to refine the hit and see if you could recover from it, e.g. see this article.

In my Chasy Maze game (https://itunes.apple.com/us/app/chasy-maze/id1139444245?mt=8) I have the puffer fish chasing the diver using Jumper. The fish have a dynamic physics body and I’m using transition.to to move them from the current node in the path to the next. If there’s a collision between the puffer fish and the diver I just cancel that transition. I haven’t had any problems relating to that.

Your idea of using “node triggers” is interesting, but does seem a little over-engineered. But if it works… :slight_smile:

 Jay

PS - The fish’s path is recalculated every time they reach the next node, so I don’t have to worry about cancelling the transition due to a new path – just collisions.

Thanks Jay,

A large issue arises when the object runs into a wall.  Since the object is up against a wall, it instantly cancels any transition I try to start.  I’m sure I could make some kind of fix to prevent this problem, but it just seems like I am making it much more complicated than it needs to be.

Yeah, mine’s different because the fish aren’t being directly controlled like my player – and he’s a physics object moved with physics calls.

If you are using pathfinding, how can the object run into a wall? A wall tile should be marked as not walkable so your path should never hit it. Is the problem that the player’s bounding box can hit a wall even when he’s in the grid cell next to a wall?

Maybe someone will have bright idea we can both learn from. I’m just getting ready to play with a tiled dungeon so I’ll be doing similar things.

 Jay

If the physics object is hit by the player, or hit with a projectile, it sometimes ends up running into a wall. It cant walk on those tiles, but its not inside of the unwalkable tile, just close enough to instantly cancel the transition away from the wall… Its a weird collision call.

I want to stay away from transitions if possible.

With the disclaimer that I’m pretty new to game development, I’m currently working on a prototype with an object following another (moving) object through a maze.

The chaser object is dynamic, moved with transitions. As said above, there shouldn’t be accidental bumps into walls. There are (planned) collisions with other objects and I just cancel the transition when that happens. Every half a second the path gets recalculated so the object starts a new transition by itself. Works quite well so far.

If you want to entirely avoid collision with certain types of walls/projectiles, you can use collision filtering (masks). Or temporarily remove the physical body of the transitioned object until the collision is resolved in some other (non-physical) way.

EDIT: Noticed the new reply after posting mine… Not sure why moving away from the path would cause the object to break the transition? Does it get stuck into the wall?

No, it doesn’t get stuck or anything.  A simple velocity change would allow it to move away from the wall. The issue is that I have the transition cancel when it collides with a wall, so when it tried to start transitioning again it instantly cancel the transition.

Transitions are very easy to implement and use normally, but I need to also implement a seeking state that frequently updates linear velocity towards the player to achieve a fluid ‘seeking’ curve.  I do not want to be using two different systems to control my AI (transitions and linear velocity).

If you’re only getting pushed against the wall, but moving parallel to or away from it, it doesn’t seem like you need to cancel. If the dot product of your direction and the hit normal isn’t positive, that would be the case, and you could just keep the transition alive.

Similarly for snagging corners and such, you could use “whiskers” on your object (via raycasts, for example) to refine the hit and see if you could recover from it, e.g. see this article.