- Home /
Camera behaviour when looking directly up or down
Hi I have a camera in my project that looks at a 3D cursor projected into the world... I'm using this code to track it:
Vector3 relPos = lookatObject.transform.position - transform.position;
Quaternion curRot = transform.rotation;
Quaternion tarRot = Quaternion.LookRotation(relPos);
transform.rotation = Quaternion.Lerp(curRot, tarRot, turnSpeed * Time.deltaTime);
lookatObject being the 3D cursor. When I look left or right the camera smoothly rotates around 360 degrees but when I look up or down the camera starts going mad (not sure how to better explain it lol) and refuses to rotate further than 90 degrees around X (I don't mind if the camera rotates to be inverted since this is a space game). This is the code that projects the cursor if it helps.
Vector3 position = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 100);
position = Camera.main.ScreenToWorldPoint(position);
transform.position = position;
Hope someone can help, thanks!
Your answer
Follow this Question
Related Questions
Camera following player gameObject,Camera follows player, with script attached. 1 Answer
How to Rotate FPS Camera independent of Parent Player Object while WallRunning ? 0 Answers
Making object Clamp to Look Rotation of Camera 1 Answer
How to make the player rotate to where an object is being thrown? 1 Answer
How do I rotate player's camera to peak around objects. (first person shooter leaning) 1 Answer