void LateUpdate() { //transform.position = pos; // asymptotic slide: // exponential slide: transform.position = AnimMath.Slide(transform.position, target.position, 0.0005f);//(pos - transform.position) * Time.deltaTime * 5; }
/// <summary> /// Turns turret towards the target /// </summary> private void TurnTowardsTarget() { if (player) // if player is set as a target { Vector3 disToTarget = player.position - transform.position; // Gets distance Quaternion targetRotation = Quaternion.LookRotation(disToTarget, Vector3.up); // Gets target rotation Vector3 euler1 = transform.localEulerAngles; // get local angles BEFORE rotation Quaternion prevRot = transform.rotation; // transform.rotation = targetRotation; // Set Rotation Vector3 euler2 = transform.localEulerAngles; // get local angles AFTER rotation if (lockRotationX) { euler2.x = euler1.x; //revert x to previous value; } if (lockRotationY) { euler2.y = euler1.y; //revert y to previous value; } if (lockRotationZ) { euler2.z = euler1.z; //revert z to previous value; } transform.rotation = prevRot; // This objects rotation turns into the prevRot transform.localRotation = AnimMath.Slide(transform.localRotation, Quaternion.Euler(euler2), .5f); // slides to rotation } else { // figure out bone rotation, no target: transform.localRotation = AnimMath.Slide(transform.localRotation, startingRotation, .05f); } }
public static Quaternion Slide(Quaternion current, Quaternion target, float percentLeftAfter1Second = .05f) { float p = 1 - Mathf.Pow(percentLeftAfter1Second, Time.deltaTime); return(AnimMath.Lerp(current, target, p)); }
public static Vector3 Slide(Vector3 current, Vector3 target, float percentLeftAfter1Second) { float p = 1 - Mathf.Pow(percentLeftAfter1Second, Time.deltaTime); return(AnimMath.Lerp(current, target, p)); }