void Update() { if (!EnableMotion) { return; } var input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); if (input.sqrMagnitude > 0) { input.Normalize(); } if (Input.GetKey(KeyCode.LeftShift)) { input *= 2; } input = Quaternion.AngleAxis(CameraControls.instance.transform.eulerAngles.y, Vector3.up) * input; inputSpeed.Smooth = input; inputSpeed.Update(); if (input.magnitude > 0.01f) { direction.Smooth = Vector3.forward.AngleTo(inputSpeed.Smooth); } transform.eulerAngles = new Vector3(0, direction.Smooth, 0); direction.Update(); Animator.SetFloat("WalkSpeed", input.magnitude); Animator.SetBool("Awake", Awake); controller.SimpleMove(inputSpeed.Smooth * Speed); }
void Update() { smoothTargetPosition.Smooth = Target.position; offset.Smooth = Vector3.Lerp(offsetClose, offsetFar, Zoom / 10f); extraZoom.Smooth = Input.GetKey(KeyCode.Tab) ? 2 : 1; angle.Smooth = Angle; smoothTargetPosition.Update(); offset.Update(); extraZoom.Update(); angle.Update(); var rot = Quaternion.Euler(0, angle.Smooth, 0); var targetPosition = smoothTargetPosition.Smooth + rot * offset.Smooth * extraZoom.Smooth; var targetRotation = rot * Quaternion.Euler(Mathf.Rad2Deg * Mathf.Atan2(offset.Smooth.y, 2 - offset.Smooth.z), 0, 0); transform.position = targetPosition; transform.rotation = targetRotation; Zoom -= Input.mouseScrollDelta.y; Zoom = Mathf.Clamp(Zoom, 0, 3); if (Input.GetMouseButton(0) || Input.GetMouseButton(1)) { float d = (Input.mousePosition.x - lastMousePosition.x) / 360; if (d > .15f) { Debug.Log(d); } if (d < .1f) { Angle += d * 180; } Angle %= 360; } lastMousePosition = Input.mousePosition; }