As the title say i trying to simulate the movement of a compass but I don’t get this working as I would like.
First this should work in the Tick and look more or less like this:
This is my first system and the only working more or less without problems atm:
The problem is this one is this don’t simulate the movement correctly as in the example cause don’t give that overlap effect before reach the correct location.
CompassLocationQuad = FQuat::Slerp( CompassLocationQuad, FQuat( GetActorRotation() * -1 ), DeltaTime * 5.f );
CompassLocation = CompassLocationQuad.Rotator().Yaw;
float CompassLocation (The final rotation float to apply)
FQuat CompassLocationQuad (The calculated rotation)
Second one:
This one give that effect but have a lock problem that idk how to fix
Using Quats:
float scalarTension = 10.f;
FQuat targetAng = FQuat( GetActorRotation() * -1 );
float scalarDamping = 4.f;
angVelQuad = angVelQuad + ((( targetAng - CompassLocationQuad ) * scalarTension) * DeltaTime - ((angVelQuad * DeltaTime) * scalarDamping) );
CompassLocationQuad = CompassLocationQuad + angVelQuad * DeltaTime;
CompassLocation = CompassLocationQuad.Rotator().Yaw;
Without Quats:
static float Adjust( float angle ) {
if ( angle > 180 ) {
FMath::Fmod( angle - 360.f, 360.f );
} else if ( angle < 180 ) {
FMath::Fmod( angle + 360.f, 360.f );
}
return angle;
}
float scalarTension = 10.f;
float targetAng = FQuat( GetActorRotation() * -1 ).Rotator().Yaw;
float scalarDamping = 4.f;
angVel += scalarTension * Adjust( targetAng - CompassLocation ) * DeltaTime - scalarDamping * angVel * DeltaTime;
CompassLocation = Adjust( CompassLocation + angVel * DeltaTime);
float CompassLocation (The final rotation float to apply)
FQuat CompassLocationQuad (The calculated rotation)
FQuat angVelQuad;
float angVel;
https://dl.dropboxusercontent.com/u/28070491/UE/Slack/General/GIFSample.gif
https://dl.dropboxusercontent.com/u/28070491/UE/Slack/General/GIFC.gif
Tried other solutions that don’t work as:
FQuat ASCharacter::CompassCalc( FQuat a, FQuat b, float InterpSpeed, float DeltaTime ) {
if ( InterpSpeed <= 0.f ) {
return b;
}
const FQuat Dist = b - a;
if ( Dist.SizeSquared() < KINDA_SMALL_NUMBER ) {
return b;
}
const FQuat DeltaMove = Dist * FMath::Clamp<float>( DeltaTime * InterpSpeed, 0.f, 1.f );
return a + DeltaMove;
}
That said, I need an example or a way to fix my code, cause no idea how fix the rotation lock or use with the Quat function this…
Thanks.