Hi,
I am using steering forces to control the movement of my AI, however I am having trouble limiting their steering for extreme turns, and turns at low velocity.
Figure 1 - where red is the velocity and green the desired direction
Figure 1 (a) is what currently happens when no limit is applied and ,ideally, I would like to implement what is seen in Figure 1 (b).
I get the total steering force that I want to apply to my pawn, get the angle to that destination and check to see if it greater than the maximum turn rate of the pawn.
//Calculate Acceleration
Acceleration = (TotalSteeringForce / I->GetMass());
//Get desired change in velocity
newVelocity = HelmData.ActualVelocity + (Acceleration * DeltaTime);
// Max Turn
if (newVelocity.Size() > 0)
{
float maxTurn = I->GetMaxTurnRate() * DeltaTime;
angleToDestination = FMath::RadiansToDegrees(acos(FVector::DotProduct(newVelocity.GetSafeNormal(), I->GetHelmComponent()->GetForwardVector().GetSafeNormal())));
if (angleToDestination > maxTurn)
{
//UE_LOG(LogTemp, Warning, TEXT("Helm Controller - Turn angle too great"));
newVelocity = CorrectVelocity(HelmData.ActualVelocity, newVelocity, maxTurn, I->GetMass(), DeltaTime);
}
}
This seems to correctly fire the CorrectVelocity function at the appropriate time, however the issue is that I struggle to limit the turn to the requested velocity based on its current velocity in a smooth fashion. This is what I have got for that function, however it doesnt seem to work at all.
//Calculate change in angle per tick
float x = (requestedVelocity.X * (cos(maxTurn))) - (requestedVelocity.Y * sin(maxTurn));
float y = (requestedVelocity.X * (sin(maxTurn))) + (requestedVelocity.Y * cos(maxTurn));
//Calculate new steering vector from mass
FVector returnVector = FVector(x, y, 0.0);
returnVector = (returnVector / (mass / 200)) * delta;
return returnVector + currentVelocity;
Does anyone know how more appropriately limit the turning velocity?