- Home /
Question is off-topic or not relevant, see Quaternion convert local to world rotation
Camera direction depending on targets slope (X axis)
I am using the Standard Assets Smoothfollow script. There is a problem: If my target is on a slope, the camera adds no extra yz-position to the corresponding slope angle. The result is that the cam is lowered in aspect to the slope. See Fig. 2. There can not be seen anything whats infront of the target.
This is the code:
public Transform target;
public float distance = 5f;
public float height = 1.3f;
public float heightDamping = 1.5f;
public float rotationDamping = 2f;
private void LateUpdate() { //TODO: Normal of ground to lift cam extra when elevation
//Angle calculation
RaycastHit hit;
Physics.Raycast (target.position, -target.up, out hit);
float angle = Vector3.Angle(Vector3.up, hit.normal);
// Calculate the current rotation angles
Quaternion wantedRotation = target.rotation;
Quaternion currentRotation = transform.rotation;
float wantedHeight = target.position.y + height;
float currentHeight = transform.position.y;
// Damp the rotation around the y-axis
currentRotation = Quaternion.Lerp(currentRotation, wantedRotation, rotationDamping * Time.deltaTime);
// Damp the height
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
// Set the height of the camera
transform.position = new Vector3(transform.position.x, currentHeight, transform.position.z);
transform.LookAt (target);
}
The above code includes the calculation for the angle of the ground. This should be added to the Quaternions x to lift the cam on the "rotation sphere". But this does not work.
any chance I could get the rest of the code with maybe some rough starting values. I'll try to help.
Follow this Question
Related Questions
making a camera that moves depending on mousepos.y 0 Answers
How to get angular difference? 2 Answers
Unity, walking up small steps with rigidbodies 2 Answers
how to get the signed angle between two quaternion? 1 Answer
Rotate angle between two points 0 Answers