Question by
alyaziaksr · Feb 22 at 12:13 AM ·
quaternionrotation axis
How do I rotate y to mouse location with the x rotation staying set?
I'm trying to rotate only the y axis to where the mouse is whereas I want the x rotation to stay 30. The code makes the x rotation 0 and if I make targetRotation.x = 30 that doesn't work either.
Plane playerPlane = new Plane(Vector3.up, transform.position);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float hitDistance = 0.0f;
if (playerPlane.Raycast(ray, out hitDistance))
{
Vector3 targetPoint = ray.GetPoint(hitDistance);
Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
targetRotation.x = 0;
targetRotation.z = 0;
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 15f * Time.deltaTime);
}
Comment
Your answer
Follow this Question
Related Questions
How to have objects rotate around a given point that are scripted to face the player 1 Answer
Quaternions rotation stuck 0 Answers
Rotating an Object (To Face Another Object) Only on X and Y Axis 3 Answers
How do I limit the roll of a game object? 0 Answers
Rotate a GameObject a fixed amount on key press struggles. Stops at 180. 1 Answer