/// <summary> /// Offsets the camera by adjusting camera's lateral and vertical position, after everything else has been calculated. /// </summary> /// <returns></returns> public override Vector3 FinalPositionOffset() { Vector3 Offset = Vector3.zero; //Vertical Offsets float cameraHeightOffset = LerpUtility.Clerp(baseCameraHeight, baseCameraHeight + maxCameraHeight, HeightOffsetCurve, LastPlayerWallPercentage()); Offset = new Vector3(0f, cameraHeightOffset, 0f); // Lateral Offset if (CameraSway && GameController.instance.state == GameController.State.Round) { Vector3 lateralDeltaMove = transform.InverseTransformDirection(currentClosestRailNodeIndex.GetWorldPosition(GetCurrentLookOffsetT() + ExtraLookAhead) - currentClosestRailNodeIndex.GetWorldPosition(GetCurrentOffsetT() + ExtraLookAhead)); if (target != null) { lateralDeltaMove = transform.InverseTransformDirection(currentClosestRailNodeIndex.GetClosestPointOnRailSpline(target.transform.position) - currentClosestRailNodeIndex.GetWorldPosition(0f)); } if (Mathf.Abs(lateralDeltaMove.x) > 2f) { currentSway = LerpUtility.Clerp(currentSway, (lateralDeltaMove.x > 0 ? -MaxXSway : MaxXSway), FollowOffsetCurve, swaySensitivity * Time.deltaTime); currentSway = Mathf.Clamp(currentSway, -MaxXSway, MaxXSway); } else { currentSway = LerpUtility.Clerp(currentSway, 0f, FollowOffsetCurve, swaySensitivity * Time.deltaTime); } Offset += transform.right * currentSway; } return(Offset); }
/// <summary> /// where to look at in the world /// </summary> public override Vector3 WhereToLook() { Transform losingPlayer = GetLosingPlayer(); // CheckpointManager.instance.GetLosingPlayer(); Vector3? avPos = target != null ? target.position : GetAveragePlayerPosition(); float lookForwardT = GetCurrentLookOffsetT(); //LerpUtility.Clerp(lookForwardOffsetT, lookForwardOffsetT + addLookForwardOffT, LookAheadOffsetCurve, LastPlayerWallPercentage()); Vector3 lookAheadPos = currentClosestRailNodeIndex.GetClosestPointOnRailSpline(currentClosestRailNodeIndex.GetWorldPosition(lookForwardT)); if (avPos.HasValue) { if (losingPlayer != null) { Vector3 lastPlayerPos = losingPlayer.position; Vector3 baseLookPos = lookAheadPos; // (lookAheadPos + avPos.Value) * 0.5f; //Vector3 LookPos = LerpUtility.Clerp(lookAheadPos, (avPos.Value + lastPlayerPos) * 0.5f, HeightOffsetCurve, LastPlayerWallPercentage()); Vector3 LookPos = LerpUtility.Clerp(baseLookPos, (avPos.Value + lastPlayerPos) * 0.5f, HeightOffsetCurve, LastPlayerWallPercentage()); return(LookPos); } else { Debug.Log("No losing player!"); return(LerpUtility.Clerp(lookAheadPos, avPos.Value, FollowOffsetCurve, LastPlayerWallPercentage())); //avPos.Value; } } else { //Debug.Log("No average pos!"); return(currentClosestRailNodeIndex.GetWorldPosition(lookForwardOffsetT)); } }
public float GetCurrentLookOffsetT() { return(LerpUtility.Clerp(lookForwardOffsetT, lookForwardOffsetT + addLookForwardOffT, LookAheadOffsetCurve, LastPlayerWallPercentage())); }
public float GetCurrentOffsetT() { return(LerpUtility.Clerp(-followOffsetT, -followOffsetT + -addFollowOffsetT, FollowOffsetCurve, LastPlayerWallPercentage())); }