Apply rotation only on X and Z axes

Asked

Viewed 103 times

1

I’m trying to rotate an object only on the X and Z axes, keeping the original value on the Y axis, but this way the rotation just doesn’t work, or gets totally misaligned.

RaycastHit hit;
if (Physics.Raycast(transform.position, -Vector3.up, out hit, layerMask))
{
    Quaternion rotation = Quaternion.RotateTowards(transform.rotation, 
            Quaternion.FromToRotation(Vector3.up, hit.normal), 5F);

    transform.rotation = Quaternion.Euler(rotation.x, transform.rotation.y, rotation.z);
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.