I'm implementing A* waypoint pathfinding with some twists. One of the problems I'm encountering is because I do not change velocities of the agents directly but rather I do so through forces.
Which gives me the following problem: let's suppose the path consists of three nodes,
P0 = the starting position P1 = node 1 P2 = node 2
When the agent starts moving, it's first target position is P1. The agents moves in that direction because I let a force F act on it's velocity: F=normalized(targetPos-agentPos)*agentAccel*agentMass;
The agent reaches P1.
Now the agent's target position is P2, and upon it will act a force in the direction of (targetPos-agentPos).
However, this is a centripetal force, meaning that the agent will most likely orbit around P2 instead of popping the next node off the path (unless the angle between [P0,P1] and [P1,P2] is small) Stopping the agent at each node is not an option (would look unnatural) What should really happen is the velocity of the agent gradually shifting towards 100% the direction of [targetPos-agentPos], and the velocity should be completely 'shifted' before a certain distance(dX) is laid off, starting from the previous node position
In order to solve this problem, only one parameter is adjustable:
- F_dir: the direction of the force acting upon the agent, that's supposed to lead the agent to the next node.
The values of the following parameters are known:
- agentAcceleration (=the magnitude of the force vector)
- agentVelocity
- agentPosition
- node positions
- targetPosition (= the next node on the path)
I've been trying some different strategies with trial and error to prevent this, but it seemed rather messy, so my question is, what is a decent approach to this problem?