private void Method_YawTurning(float inputValue)
{
// Convert Deg to Rad -------------------------------------------------------------|
float yawTurnSpeedInRad = yawTorqueSpeed * Mathf.Deg2Rad;
// Account for AngularDrag --------------------------------------------------------|
float dragTorque = sRigidbody.angularDrag * sRigidbody.angularVelocity.y;
// Account for Angular Turning "speed" --------------------------------------------|
float requiredTorqueForce = sRigidbody.inertiaTensor.y * yawTurnSpeedInRad;
// Calculate net torque (desired - drag) ------------------------------------------|
float netTorque = requiredTorqueForce - dragTorque;
// Aplly Torque only if the input is not equal to zero
if (inputValue != 0f)
{
// Change the vehicle rigidbody ( I do this because I like to personalize where the "rotation takes place" ) so I can create different behaviours to create variety.
sRigidbody.automaticCenterOfMass = false;
sRigidbody.centerOfMass = yawCenterOfMassOffset.localPosition;
// Check if players prefer to play with inverted steering controls
if(invertSteering == true) { inputValue *= -1f; }
//else { inputValue *= 1f; }
// Aplly Torque
// DESCOBRI UM ERRO : o torque esta em relação ao eixo do mundo e não dele mesmo,
// SE usar .right ao inves do .up pelo menos...
sRigidbody.AddRelativeTorque(gameObject.transform.up * netTorque * inputValue, ForceMode.Force);
}
else sRigidbody.automaticCenterOfMass = true;
Debug.DrawRay(gameObject.transform.position, gameObject.transform.right * 10, Color.yellow);
}