Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Start()
- {
- Vector3 angles = transform.eulerAngles;
- rotationYAxis = angles.y;
- rotationXAxis = angles.x;
- // Make the rigid body not change rotation
- if (GetComponent<Rigidbody>())
- {
- GetComponent<Rigidbody>().freezeRotation = true;
- }
- }
- void LateUpdate()
- {
- if (target)
- {
- if (ControlFreak2.CF2Input.GetMouseButton (0)) {
- velocityX += xSpeed * ControlFreak2.CF2Input.GetAxis ("Mouse X") * 0.02f;
- velocityY += ySpeed * ControlFreak2.CF2Input.GetAxis ("Mouse Y") * 0.02f;
- }else{
- velocityX += xSpeed * Input.GetAxis ("Horizontal2") * 0.02f;
- velocityY += ySpeed * Input.GetAxis ("Vertical2") * 0.02f;
- }
- rotationYAxis += velocityX;
- rotationXAxis -= velocityY;
- rotationXAxis = ClampAngle(rotationXAxis, yMinLimit, yMaxLimit);
- Quaternion fromRotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, 0);
- Quaternion toRotation = Quaternion.Euler(rotationXAxis, rotationYAxis, 0);
- Quaternion rotation = toRotation;
- distance = Mathf.Clamp(distance - ControlFreak2.CF2Input.GetAxis("Mouse ScrollWheel")*Seconds, distanceMin, distanceMax);
- Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);
- Vector3 position = rotation * negDistance + target.position;
- transform.rotation = rotation;
- transform.position = position;
- velocityX = Mathf.Lerp(velocityX, 0, Time.unscaledDeltaTime * smoothTime);
- velocityY = Mathf.Lerp(velocityY, 0, Time.unscaledDeltaTime * smoothTime);
- }
- }
- public static float ClampAngle(float angle, float min, float max)
- {
- if (angle < -360F)
- angle += 360F;
- if (angle > 360F)
- angle -= 360F;
- return Mathf.Clamp(angle, min, max);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement