Apply rotation only on X and Z axes

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 simply does not work, or it 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);
}
    
asked by anonymous 08.12.2016 / 12:24

0 answers