Support Forum

Pathfinding when movement uses Physics Impulse and Bounces?

Hi, I’m looking for advice on how to use the AStar project plugin to do pathfinding for my game in which character movement is only done using Rigidbody2D.AddForce() of type ForceMode2D.Impulse. Also, bouncing off walls and obstacles is possible and ideally this would be used when pathfinding. Here is an example screen shot, where the red, AI controlled, token is finding a path to the blue enemy token using standard pathfinding.

As you can see, while it can find a path, since I’m just applying an impulse force to the red token, I don’t use this path exactly and instead I’ve tried finding the closes point on the path which the token has line of sight to, shooting toward it, then calculating a path again after the token has stopped moving. This method is very brute force and doesn’t always work out.

Is there something else I should try? I’m guessing much of this is outside the scope of the package. But I thought others might have some ideas. Can the pathfinder understand the use of physics in an agent’s movement? Can it find paths by utilizing bounces off obstacles?

Hi

The built-in movement scripts are not intended for highly physics driven characters. A custom movement script is to be recommended (https://arongranberg.com/astar/docs/custom_movement_script.html).
Generally if agent doesn’t follow the path exactly I would recommend that you recalculate the path pretty often (maybe as often as many times per second). In such a small map that you have, recalculating the path is very fast so I wouldn’t worry about it much.