Small update - I’ve tweaked this a bit to also do some location offset based on the lag/lead and I think the results are pretty good.
If anyone’s interested, here’s the updated version of the UpdateLocRot function:
void APWNWeapon::UpdateLocRot(FVector newLoc, FRotator newRot, float deltaTime)
{
FRotator finalRot = newRot;
// Rotation Leading/Lag
float lagDiff;
finalRot.Pitch = LagWeaponRotation(newRot.Pitch, LastRotation.Pitch, deltaTime, MaxPitchLag, 1, lagDiff);
finalRot.Yaw = LagWeaponRotation(newRot.Yaw, LastRotation.Yaw, deltaTime, MaxYawLag, 0, lagDiff);
finalRot.Roll = newRot.Roll;
// Location offset
float locDiff = lagDiff / MaxYawLag;
locDiff *= MaxLocLagX;
//UPWNGameGlobals::Log(TEXT("YAW"), lagDiff, true);
ArmMesh->SetRelativeLocation(FVector(ArmMeshOffset.X, ArmMeshOffset.Y + locDiff, ArmMeshOffset.Z), false);
// Set our loc
LastRotation = newRot;
this->SetActorLocation(newLoc);
this->SetActorRotation(finalRot);
//ArmMesh->SetRelativeRotation(finalRot);
}
P.S. you will also have to add the following variable declaration to your header:
/** Max Location Lag - X */
float MaxLocLagX = 5.0f;