- Home /
Clamping a Manipulated Camera
Here is my dilemma:
EDIT: I forgot to explain what this is doing. The camera is able to be rotated around the player using the right analog stick.
While the horizontal rotation is acceptable as a 360 degree rotation, the vertical camera should only be limited to a certain angle in relation to the player. I understand moving objects can be clamped using 'Mathf' and eulers, but my question is whether or not I can clamp something controlled by an axis using those conventional methods? I am stumped as to where I would introduce the parameters.
Any help is greatly appreciated.
Here is the code:
public class FollowCam : MonoBehaviour {
public float turnSpeed = 4.0f;
public Transform player;
private Vector3 offset;
void Start () {
transform.LookAt(player.position);
offset = transform.position - player.position;
}
void LateUpdate()
{
offset = Quaternion.AngleAxis (Input.GetAxis("RightHorizontal") * turnSpeed, Vector3.up) * offset;
offset = Quaternion.AngleAxis (Input.GetAxis("RightVertical") * turnSpeed, Vector3.right) * offset;
transform.position = player.position + offset;
transform.LookAt(player.position);
}
}
Comment
Your answer
Follow this Question
Related Questions
No Glitch Please ... 1 Answer
Why is my camera switching angles? 0 Answers
Unity freezes on play 2 Answers
Toggle between scripts with a script? 2 Answers
Randomly Generated Objects 1 Answer