A* Pathfinding Project

AIPath Rotation causes agent to "strafe"


So I’m hoping there is an easy fix to this, because otherwise A*ppp does everything I want it to do.

Currently Im making a tracked/tank like unit for a RTS, and have them running with seekers and AI Path; they go where I want them to go, however, when I turn their rotation speed down, they tend to start to “slip” sideways in a very un-vehicle like fashion when their not generally already facing the direction they need to go.

Ex: the unit is facing ‘forward’ and I send a move point that is ‘behind’ it. this results in the unit starting to “slip” sideways once its rotated within 90 degrees of its desired movement vector. Not much, but noticeably.

I have rotation speed set to 45, and “Slow when not facing target” enabled, which gets closer to the effect desired. However, the degree to which the slip is apparent is noticeable, and not adjustable where I can find it. If there isn’t an exposed setting to adjust the forward-movement-while-not-pointed-exactly, is there a variable that can be adjusted in the code?



All the built-in movement scripts are written for characters like humans that can turn more freely. Depending on how realistic you need the motion to be it might be possible for you to just tweak some constants in the AIPath class.

In particular in MovementUtiltities.cs there is this line:

// Lower the speed when the character's forward direction is not pointing towards the desired velocity
// 1 when velocity is in the same direction as forward
// 0.2 when they point in the opposite directions
float directionSpeedFactor = Mathf.Clamp(dot+0.707f, 0.2f, 1.0f);

You could change that 0.2 to 0.0 to make it slow down even more when not facing the desired direction.

Movement scripts for vehicles have a whole bunch of other constraints that make them harder to write and also more dependent on the details of the game. For example a vehicle might be in a narrow corridor and calculates a path which would require it to turn around. The corridor might be narrower than the vehicle’s turning radius so it might have to do a three point turn or something like that. Depending on the game a rotation on the spot might be acceptable though. If you look at games such as Company of Heroes 2 the vehicles fall back to turning on the spot in some cases.

Here is a nice article about how the game Company of Heroes does it. It’s probably too complex for most games though, but it might provide some useful insights.
https://send.firefox.com/download/83147a5e942a7ad8/#Q_qYpdyV5TvtvLiwogdZ7g (note: the link expires in 7 days)