#Why doesn't this work?

1 messages · Page 1 of 1 (latest)

kind gate
#

What's your expected result ?

loud elk
#

my expected result is that it rotates smoothly to the X target rotation

kind gate
#

🤔 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

loud elk
#

the object is like vibrating in place instead of rotating

kind gate
#

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 );

loud elk
#

i'm gonna try it out

kind gate
#

Ok there is any issue if transform.rotation.eulerAngles.x < 0

loud elk
#

it works!

#

thank you very much

kind gate
#

Nice !

#

In case you want transform.rotation.x to be negative you will need some more code

loud elk
#

i do need that

#

because it's freaking out whenever I do a negative transformation

kind gate
#

Yep haha, it's because -90° rotation equals 270° rotation, so everything is kind of exploding

loud elk
#

how do I fix that tho

kind gate
#

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

loud elk
#

Is there no way to make it smooth?

kind gate
#

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 😄

loud elk
#

alright

#

it works in both directions now

#

thanks a lot

kind gate
#

No prob 😄 if you want to rotate around Y and Z just modify the 0 values in myTargetRotationVector

loud elk
#

wanna see what I'm working on?

kind gate
#

Sure 👀

loud elk
#

Based on midi

kind gate
#

So cool ! So you play the sound and all the animation is calculated ?