I have an actor that has an FRotator as a property (for adjusting hand roation). Whenever I try to set the Rotator to the angle I want (I tried both in code and manually with these values):
But the Rotator values automatically change to some seemingly random numbers. Why can I not set the rotator to the values I specify? Is it trying to prevent Gimbal Lock or something? I tried updating to 4.26 also but it happened to me there too.
Here is what my constructor looks like:
ABaseWeapon::ABaseWeapon() : Super()
{
myWeaponType = EWeaponType::VE_ONE_HANDED;
myDamageModifier = 0;
myIsEquipable = true;
myIsAutomaticallyEquipped = true;
myIsFullAutomatic = false;
//Set the local rotation/locations for when the item is grabbed/equipped.
myOnGrabItemTransform = FTransform(FRotator::ZeroRotator, FVector::ZeroVector);
myRightHandHoldTransform = FTransform(FRotator(0.0f, -90.0f, 90.0f)), FVector::ZeroVector);
myLeftHandHoldTransform = FTransform(FRotator(180.0f, -90.0f, 90.0f), FVector::ZeroVector);
}
But once I load in, here is what the values look like:
I read in another post that this is how Rotators work and that they apparently add together their values? If thats the case then how do you specify an exact Rotator value without it being changed.
I Initialize it in the constructor of the class with the above posted code. But even when I try to manually change it in the editor, it automatically changes it immediately.
That is not a problem - it is just floating point thing. Floats are stored in memory with constrained precision, so there is always a chance for them to lose last digit precision.
Thanks again for the help Kehel. The issue your describing though I think is different from the issue I’m having with FTransform’s rotator. What your describing is when you type in 90 for one of the components, it changes to 89.99999999 in editor. But this issue is I put in 0, 90, -90 and it changes to like -104.3654, -90, 26.8530.
Instead of using two FTransforms for myRightHandHoldTransform and myLeftHandHoldTransform, I’m instead using two FRotators (myRightHandHoldRotation and myLeftHandHoldRotation) and two FVectors (myRightHandHoldLocation and and myLeftHandHoldLocation) this solved the problem for me.
As to why this is happening? No idea. My guess is that an FTransform is doing some behind the scenes calculation but I wasen’t able to find the reason as to why, Like I said; the numbers seem random every time you click a component in the FRotator part of the FTransform.
Perhaps but if thats the case, the value I provided should have still worked and would be equal to (0, 90, -90). For example, If I take a cartesian coordinate and convert it to polar coordinate I can then go backwards and convert from polar back to the same cartesian coordinate. In this case, the values are completely random each time I click one of the yaw, pitch, roll, components.