Hello,
I want to rotate my camera around an object while the object can rotate by itself.
Rotating my camera before the object rotated works fine but when the object has already rotated the rotation gets messed up.
This is my code so far:
void OrbitCamera() //rotate the Camera
{
if(Input.GetMouseButtonDown(1) == true)
{
lastMousePos = Input.mousePosition;
}
if(Input.GetMouseButton(1) == true) //right Mousebutton pressed?
{
Vector3 currentMousePos = Input.mousePosition;
Vector3 mouseMovement = currentMousePos - lastMousePos; //the Movement of the Mouse
Vector3 posRelativeToRig = TheCamera.transform.localPosition;
Vector3 rotationAngles = mouseMovement / OrbitSensitivity;
if(HoldToOrbit)
{
rotationAngles *= Time.deltaTime;
}
//Quaternion theOrbitalRotation = Quaternion.Euler( rotationAngles.y, rotationAngles.x, 0);
//posRelativeToRig = theOrbitalRotation * posRelativeToRig;
TheCamera.transform.RotateAround(cameraRig.position, TheCamera.transform.right, -rotationAngles.y);
TheCamera.transform.RotateAround(cameraRig.position, TheCamera.transform.up, rotationAngles.x);
Quaternion lookRotation = Quaternion.LookRotation(- TheCamera.transform.localPosition);
TheCamera.transform.rotation = lookRotation;
if(HoldToOrbit == false)
{
lastMousePos = currentMousePos;
}
}
}
I would appreciate any help.
Thanks!