void UpdatePivotElement(float stiffnessPos) { Vector3 desiredPosition; CubeController.CarStates carState = _car.GetComponentInChildren <CubeController>().carState; bool grounded = carState == CubeController.CarStates.AllWheelsGround || carState == CubeController.CarStates.AllWheelsSurface; if (grounded) { desiredPosition = _car.position + _car.up * cameraHeight; } else { desiredPosition = _car.position + Vector3.up * cameraHeight; } _pivotPosition = Vector3.Lerp(_pivotPosition, desiredPosition, stiffnessPos * Time.deltaTime); }
void UpdateCamPositon(float stiffnessPos) { Vector3 desiredPosition; CubeController.CarStates carState = _car.GetComponentInChildren <CubeController>().carState; bool grounded = carState == CubeController.CarStates.AllWheelsGround || carState == CubeController.CarStates.AllWheelsSurface; if (_isBallCam) { desiredPosition = _pivotPosition + (_car.position - _ball.position).normalized * cameraDist; } else { if (grounded) { desiredPosition = _pivotPosition - _car.forward * cameraDist; } else { desiredPosition = _pivotPosition - _car.GetComponent <Rigidbody>().velocity.normalized *cameraDist; } } desiredPosition = AddRotation(desiredPosition); if (grounded) { transform.position = Vector3.Lerp(transform.position, desiredPosition, stiffnessPos * Time.deltaTime); } else { if (Mathf.Abs(_checkVelocity.x) < 3f && Mathf.Abs(_checkVelocity.z) < 3f) { transform.position = Vector3.Lerp(transform.position, desiredPosition, 0.01f * stiffnessPos * Time.deltaTime); } else { transform.position = Vector3.Lerp(transform.position, desiredPosition, 0.4f * stiffnessPos * Time.deltaTime); } } }