// Update is called once per frame void LateUpdate() { // When player clicks on right mouse button if (Input.GetButton("Fire2")) { // Changing the pitch when player is holding right click float mouseAxisY = Input.GetAxis("Mouse Y"); float mouseAxisX = Input.GetAxis("Mouse X"); theTargetYaw += mouseAxisX * mouseXSensitivity; theTargetPitch += mouseAxisY * mouseYSensitivity; } // Changes the pich rotation theTargetPitch = Mathf.Clamp(theTargetPitch, -85, 85); // Clamping the rotation so the camera doesn't get stuck or freak out at 90 degrees // Easing thePitch = OrbitalMathAnim.SlidingEffect(thePitch, theTargetPitch, .05f); theYaw = OrbitalMathAnim.SlidingEffect(theYaw, theTargetYaw, .05f); // Rotating using Quaternion transform.rotation = Quaternion.Euler(thePitch, theYaw, 0); float scrollWheel = Input.GetAxisRaw("Mouse ScrollWheel"); // Gets value when player uses the scroll wheel theTargetDollyDis += scrollWheel * mouseScrollMultiplier; theTargetDollyDis = Mathf.Clamp(theTargetDollyDis, TargetObject.distanceZoomMin, TargetObject.distanceZoomMax); // clamps the zoom theDollyDistance = OrbitalMathAnim.SlidingEffect(theDollyDistance, theTargetDollyDis, .05f); // Sliding effect when the player zooms in and out assignedCams.transform.localPosition = new Vector3(0, 0, -theDollyDistance); // Zooms in and out by using Vector3 }
public static Vector3 SlidingEffect(Vector3 currentPos, Vector3 theTarget, float percentageLeft, float dt = 0) { if (dt == 0) { dt = Time.deltaTime; } float percent = 1 - Mathf.Pow(percentageLeft, dt); return(OrbitalMathAnim.LerpFunc(currentPos, theTarget, percent)); }
// Calculates the Sliding Effect when called public static float SlidingEffect(float currentPos, float theTarget, float percentageLeft, float dt = 0) { if (dt == 0) { dt = Time.deltaTime; } float percent = 1 - Mathf.Pow(percentageLeft, dt); return(OrbitalMathAnim.LerpFunc(currentPos, theTarget, percent)); // Uses the lerpFunc to to calculate the lerp, then sends back the value }
void FixedUpdate() { time = time + Time.deltaTime * orbitSpeed * HUDTimeSlider.timeScale; // This controls the time. HUDTimeSlider.timeScale makes the time rewind, fast forward, pause, and resume. Vector3 PlanetOrbitVectorXZ = OrbitalMathAnim.OrbitAroundTarget(revolveRadius, time, orbitPosition); if (coplanar) { coplanarOrbit = OrbitalMathAnim.coplanarOrbit(revolveRadius, time, orbitPosition, cAmount); } transform.position = revolveAroundObject.position + PlanetOrbitVectorXZ + coplanarOrbit; // calulates the position for the planets and moons during their animation }
void FixedUpdate() { if (tweenTime < tweenDur) { tweenTime += Time.unscaledDeltaTime * quickerTransition; quickerTransition++; } Vector3 trailingPOS = OrbitalMathAnim.SlidingEffect(transform.position, targetToLock.transform.position, .001f, Time.unscaledDeltaTime); float result = tweenTime / tweenDur; transform.position = OrbitalMathAnim.LerpFunc(trailingPOS, targetToLock.transform.position, Mathf.Clamp(result, 0, 1)); print(result); }