Linear Velocity from Rotation

Hello. I have an issue with some velocity calculations and because my knowledge on how rotations works is limited i am struggling a bit. The project I’m working on its in VR.

So Im flying a drone in all direction and when I want to turn I just snap the ship X degrees, with AddControllerYawInput.

The hand are meshes that are a child of the ship so I moved them based on the controllers and also based on the ship so when the ship moves they move as well.

What I want is when I rotate the ship and the hand are rotating as well with it to find the velocity vector created by the rotation.

What I have in one function that I call once when the snap button is pressed:

AddControllerYawInput(45.0f);
float rotationPerSnap= 45; // Degrees of rotation per frame, the same as above


//I convert the degrees to radians and get the angular velocity vector

float YawRotationRadians = FMath::DegreesToRadians(rotationPerSnap);
FVector AngularVelocityVector = FVector(0.0f, 0.0f, YawRotationRadians); 


//Here I try to get the vector from the middle of the ship to the hand so basically the radius

 RightHandRadiusVector = rightHandMesh->GetComponentLocation() - shipMesh->GetComponentLocation();
 LeftHandRadiusVector =  leftHandMesh->GetComponentLocation() - shipMesh->GetComponentLocation();


 //And from what Ive seen onlune this is the formula to get the linear velocity from the rotation:

 RightHandLinearVelocityFromRot = FVector::CrossProduct(AngularVelocityVector, RightHandRadiusVector);

 LeftHandLinearVelocityFromRot = FVector::CrossProduct(AngularVelocityVector, LeftHandRadiusVector);


The vectors I get are completelly wrong direction and size. Any tips ?

this is one of the reasons the engine utilizes Euler Angles for rotations as FRotator and doing rotational snaps in VR (without blinking the screen) might not be the most inviting if not will get people sick

cache the FRotator PreviousRotation as probably a member of your Character.

the PreviousRotation and FRotator CurrentRotation (local function variable) would just be based off the GetActorRotation(), and your radii is the Distance of your RightHandRadiusVector.Length() and LeftHandRadiusVector.Length respectively

your Angular Velocity/Speed is just DeltaAngle/ DeltaT, so this would be a use for Tick() to clean DeltaTime
where Linear Velocity is Angular Velocity * Radius

and to save a bit of computation 45-Degrees in Radians is Pi/4 or ~ 0.785f, though I still would suggest not using arbitrary snaps of the VR camera.

1 Like