Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Global variables
- private const float STRAFE_SCALE = 0.1f;
- private Rect movingRect;
- private const float MAX_DISTANCE = 1400f;
- float distance = 200f;
- void Start ()
- {
- float w = Screen.width * 0.6f;
- float h = Screen.height * 0.7f;
- movingRect = new Rect ((Screen.width - w) / 2f, (Screen.height - h) / 2f, w, h);
- //...
- }
- void Update ()
- {
- Quaternion rotation = Quaternion.Euler (40f, rotationX, 0);
- float movingX = 0.0f;
- float movingY = 0.0f;
- Vector3 mouse = Input.mousePosition;
- //Bound Camera Strafe
- if (mouse.x > movingRect.xMax)
- movingX += STRAFE_SCALE * (mouse.x - movingRect.xMax);
- else if (mouse.x < movingRect.xMin)
- movingX += STRAFE_SCALE * (mouse.x - movingRect.xMin);
- else
- movingX = 0;
- if (mouse.y > movingRect.yMax)
- movingY += STRAFE_SCALE * (mouse.y - movingRect.yMax);
- else if (mouse.y < movingRect.yMin)
- movingY += STRAFE_SCALE * (mouse.y - movingRect.yMin);
- else
- movingY = 0;
- tran += rotation * new Vector3 (movingX, 0, movingY);
- tran.y = 0f;
- tran.x = Mathf.Clamp (tran.x, -MAX_DISTANCE, MAX_DISTANCE);
- tran.z = Mathf.Clamp (tran.z, -MAX_DISTANCE, MAX_DISTANCE);
- //...
- Vector3 dist = rotation * new Vector3 (0, 0, -distance);
- transform.rotation = rotation;
- transform.position = GetSmoothedHeightAt (tran) + dist;
- }
Advertisement
Add Comment
Please, Sign In to add comment