Question by
mcronline · May 24, 2017 at 07:41 AM ·
quaternioneuler
X and Z rotating to the same direction using Quaternion.Euler
Hi
I'm trying to rotate an object on his Y axis based on his velocity on the X axis position. Like this:
void Update(){
Quaternion rotation;
float velocityX;
velocityX = (transform.position.x - previousPosX) / Time.deltaTime;
rotation = Quaternion.Euler(-90f, velocityX, 0.0f);
transform.rotation = rotation;
previousPosX = transform.position.x;
}
As you can see, the x rotation must be fixed to -90.
Using velocityX in y parameter, the object doesn't rotate in the direction I need to. if I try to use velocityX in the z parameter, it rotates in the same wrong direction. Why this happens?
The initial transform.rotation of the object is -90, 0, 0
Thank you!
Comment
Answer by DarkFang100 · Feb 02, 2018 at 02:14 AM
Have you tried rotating the x? Like this:
Quaternion rotation;
float velocityX;
velocityX = (transform.position.x - previousPosX) / Time.deltaTime;
rotation = Quaternion.Euler(velocityX, 0.0f 0.0f);
transform.rotation = rotation;
previousPosX = transform.position.x;
Hope this helps @mcronline.
Of course, this still goes into the update function (all of it) @mcronline.