- Home /
Rotating camera around player on both axis but stops before the ground
I can't find how to move my camera around the player but stop it before it reaches the ground. Here's my code:
void Start()
{
offset = new Vector3(player.position.x + camPosX, player.position.y + camPosY, player.position.z + camPosZ);
transform.rotation = Quaternion.Euler(camRotationX, camRotationY, camRotationZ);
transform.LookAt(player.position);
}
// LateUpdate is called after Update each frame
void LateUpdate()
{
offset = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * turnSpeed, Vector3.up) * Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * turnSpeed, Vector3.right) * offset;
transform.position = player.position + offset;
transform.LookAt(player.position);
}
Answer by look001 · Jul 26, 2017 at 07:35 PM
https://www.youtube.com/watch?v=sNmeK3qK7oA To stop the camera from moving through the ground you will have to add a collider to the camera. If the collider hits something it will stop rotating further down.
Thank you, but do you think there is a way to do it from code?
Your answer
Follow this Question
Related Questions
3rd Person Orbit Camera in LOCAL Space 0 Answers
Rotate Camera to the object 0 Answers
camera movments fixed.. character controller without using character controller -.-' 2 Answers
How to rotate camera around an object to a certain amount of degrees? 2 Answers
How do I make a camera add torque on two different axis? 0 Answers