- Home /
Question by
awplays49 · Dec 24, 2014 at 11:10 PM ·
clampmathf.clamp
Strange vibrating when moving camera view
I want this to move above the player in a circular movement and always face the player, and have it clamped between behind the player and above him.
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
public int Sensitivity;
private float MouseY;
private float MouseYSet;
private float XRot;
private float YPos;
private float ZPos;
public GameObject CameraTarget;
void Start () {
}
void Update () {
// Rotation controls
MouseY += Input.GetAxisRaw ("Mouse Y");
transform.localRotation = Quaternion.Euler (Mathf.Clamp (transform.localRotation.x, 0, 90), transform.localRotation.y, transform.localRotation.z);
transform.localPosition = new Vector3 (transform.localPosition.x, Mathf.Clamp (transform.localPosition.y, CameraTarget.transform.localPosition.y + CameraTarget.transform.lossyScale.y / 2, CameraTarget.transform.localPosition.y + 50), Mathf.Clamp (transform.localPosition.z, CameraTarget.transform.localPosition.z, CameraTarget.transform.localPosition.z + 50));
if (MouseYSet != MouseY)
{
transform.Rotate (new Vector3 (-(MouseY - MouseYSet) * Sensitivity * 10, 0, 0));
transform.Translate (new Vector3 (0, -(MouseY - MouseYSet) * Sensitivity * 10, -(MouseY- MouseYSet) * Sensitivity * 10));
MouseYSet = MouseY;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Such thing as a smooth clamp? 1 Answer
my MainChara shakes when the Mathf.Clamp stops it from going off screen 1 Answer
Camera rotating past clamp 0 Answers
Cant Clamp 1 Answer
How to clamp player to viewport constraints when rotating 1 Answer