Problem:
Hi all, I want to Rotate a objects Z axis back to 0 slowly but I only want to rotate it’s Z axis and It has to be slow so that if the player is moving on the Z axis with the controls for movement it won’t be obstructed by this script adjusting the Z axis.
Question:
Here is a script a friend gave me, but I don’t know how to do just the Z axis could someone point me in the right direction?
Script:
var target: Transform;
var speed: float = 25.0;
function Update () {
var step = speed * Time.deltaTime;
var v3 = target.right - (Vector3.Dot(target.right, transform.forward) * transform.forward);
var q = Quaternion.FromToRotation(transform.right, v3);
transform.rotation = Quaternion.RotateTowards(transform.rotation, q, step);
}
Answer: (by @Vunpac)
so the final code should look like this
var speed: float = 1;
function Update ()
{
var wantedrotation = Vector3(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, 1);
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(wantedrotation), Time.time * speed);
}
and once attached to the desired object it Rotates the objects Z axis back to 0