- Home /
Question by
sleepercreeper1 · Sep 08, 2018 at 04:09 AM ·
quaternionheirarchy
rotate a child for some axis but not others
i would like to have a camera rotate on the x axis through a script , but the one pictured bellow rotates on the right axis, but keeps the other axis at 0, rather than letting it rotate with the parent. many thanks in advance
using System; using UnityEngine;
public class CameraThree : MonoBehaviour { public float mouseSensitivity = 100.0f; public float clampAngle = 80.0f;
private float rotX = 0.0f; // rotation around the right/x axis
void Start ()
{
Vector3 rot = transform.localRotation.eulerAngles;
rotX = rot.x;
}
void Update ()
{
float mouseY = -Input.GetAxis("Mouse Y");
rotX += mouseY * mouseSensitivity * Time.deltaTime;
rotX = Mathf.Clamp(rotX, -clampAngle, clampAngle);
Quaternion localRotation = Quaternion.Euler(rotX, 0, 0.0f);
transform.rotation = localRotation;
}
}
Comment
Your answer
Follow this Question
Related Questions
Add rotation to rigidbody AddForce? 3 Answers
with quaternion how rotate around global Y ? 2 Answers
Off Screen direction indicator HUD element / wrestling with Quaternion 1 Answer
Stage selection problem 1 Answer
How do I use this current Quaternion to make GameObject Joints move Correctly? 0 Answers