#Why doesn't this work?
1 messages · Page 1 of 1 (latest)
my expected result is that it rotates smoothly to the X target rotation
🤔 maybe you need to transform.rotation.eulerAngles.xotherwise it's the quaternion x value and not the one in degree
You smooth is maybe too short, you are going from transform.rotation.xto targetRotation in 0.1 seconde which may look FAST
the object is like vibrating in place instead of rotating
Let me open a new cs file 😄
Works fine with :
float Angle = Mathf.SmoothDamp( transform.rotation.eulerAngles.x, targetRotation, ref rotationVelocity, 0.1f ); transform.rotation = Quaternion.Euler( Angle, 0, 0 );
i'm gonna try it out
Ok there is any issue if transform.rotation.eulerAngles.x < 0
Nice !
In case you want transform.rotation.x to be negative you will need some more code
Yep haha, it's because -90° rotation equals 270° rotation, so everything is kind of exploding
how do I fix that tho
I think, the best way to code it is to use Quaternion.RotateTowards
The function take a from rotation and a to rotation and rotate slowly from the first to the second
Is there no way to make it smooth?
RotateTowards make it smooth, you can specift the max angle per call as a parameter
//The angle in degrees to reach, so targetRotation on X and 0 on Y and Z
Vector3 myTargetRotationVector = new Vector3( targetRotation, 0f, 0f );
//This line converts the Euler Angles ( in degrees ) to a Quaternion
Quaternion myTargetRotation = Quaternion.Euler( new Vector3( targetRotation, 0f, 0f ) );
//We apply the rotation from transfrom.rotation to myTargetRotation, 0.1f is the max angle par frame high value means high speed
transform.rotation = Quaternion.RotateTowards( transform.rotation, myTargetRotation, 0.1f );
Try this it should work in any case and any axis 😄
No prob 😄 if you want to rotate around Y and Z just modify the 0 values in myTargetRotationVector
wanna see what I'm working on?
Sure 👀
So cool ! So you play the sound and all the animation is calculated ?