- Home /
Question by
Vadom6 · Dec 19, 2019 at 03:58 AM ·
vector3camera-movementcamera rotateclampclamped rotation
Camera Clamping Third Person?
Hi I am trying to create a basic camera system which at the moment moves the way I want it to except for the x axis going to high and to low in relation to the camera target. How would I be able to clamp the x axis. I am using a secondary objects rotation to position my camera so I know I have to clamp how far that object can rotate but I am unsure how to.
I wish to use the constraintsX float to be the value for the clamp.
Here is my code:
public GameObject target;
public float rotateSpeed = 5;
public float constraintsX;
Vector3 offset;
void Start()
{
offset = target.transform.position - transform.position;
}
void LateUpdate()
{
float horizontal = Input.GetAxis("Horizontal") * rotateSpeed;
float vertical = Input.GetAxis("Vertical") * rotateSpeed;
target.transform.Rotate(0, horizontal, 0, Space.World);
target.transform.Rotate(vertical, 0, 0);
float desiredAngleY = target.transform.eulerAngles.y;
float desiredAngleX = target.transform.eulerAngles.x;
Quaternion rotation = Quaternion.Euler(desiredAngleX, desiredAngleY, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt(target.transform);
//Property of Vadom
}
Thanks In Advance for your help
Comment
Your answer
Follow this Question
Related Questions
Clamping rotation of an object 0 Answers
Adjust camera orientation through code 0 Answers
Clamp horizontal rotation based on current direction 0 Answers
I can't figure out how to clamp it 2 Answers
How to Math.f Clamp this 0 Answers