- Home /
Question by
awplays49 · Dec 24, 2014 at 09:23 PM ·
not workingclamp
Clamps not working! :(
I have 3 or 4 clamps and they dont seem to be working :(
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");
XRot = transform.rotation.x;
YPos = transform.position.y;
ZPos = transform.position.z;
XRot = Mathf.Clamp (XRot, 90, 270);
YPos = Mathf.Clamp (YPos, CameraTarget.transform.position.y, CameraTarget.transform.position.y + 50);
ZPos = Mathf.Clamp (ZPos, CameraTarget.transform.position.z - 40, CameraTarget.transform.position.z);
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
Well you're setting clamps on the XRot YPos and ZPos but then setting the transform based on other variables. Output Debug.Log for XRot YPos ZPos bet they stay withing the clamps but the transform isn't.
Yea, heres the new question. apologies
http://answers.unity3d.com/questions/862033/vertical-camera-movement-script-being-extremely-wi.html
@$$anonymous$$mmpies