in the pre-written script made by Unity, to make the camera follow an object, i would like the angle to not point towards “0” (eulerAngles.y here) but a bit more up, so that the camera is not pointing to the feet of my character.
But i can’t find out how to modify this, when i directly change the eulerAngle to a number, it rotates itself around the character from left to right instead of up/down.
Would you know how i could achieve this? (make the camera look a bit up, towards the trunk of the character for example)
Here is the code of the script attached to the camera (ball is the target) :
// Calculate the current rotation angles Debug.Log("ball.eulerAngles.y : "+ball.eulerAngles.y); var wantedRotationAngle = ball.eulerAngles.y;/* HERE, if i change the angle, it goes left/right instead of up/down) */ var wantedHeight = ball.position.y + height; var currentRotationAngle = transform.eulerAngles.y; var currentHeight = transform.position.y; // Damp the rotation around the y-axis currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime); // Damp the height currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime); // Convert the angle into a rotation var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0); // Set the position of the camera on the x-z plane to: // distance meters behind the ball transform.position = ball.position; transform.position -= currentRotation * Vector3.forward * distance; // Set the height of the camera transform.position.y = currentHeight; // Always look at the ball transform.LookAt (ball); }