private void CalculateTorque()
{
var torque = Vector3.zero;
// Handle worse when laden
float handleMod = 1.0f; // CalcHandlingMassMult();
// Check if moving slowly, increase control if slow
if (m_myRigid.velocity.magnitude <= highControlSpeedThreshold)
{
handleMod *= highControlMult * (1 - (m_myRigid.velocity.magnitude / highControlSpeedThreshold));
}
// Reverse
float reverseMult = 1;
if (throttle < 0 && m_myRigid.velocity.sqrMagnitude < 0)
{
reverseMult = -1;
}
// Part damage modifiers
float tempNotUsed = 0.0f;
float leftBallRollMult = 0.0f, leftBallPopVal = 0.0f,
rightBallRollMult = 0.0f, rightBallPopVal = 0.0f;
bool leftBallDest = GetPartInputMults(ShipPartDestroy.EShipPartType.LEFT_BALLOON, out leftBallRollMult, out leftBallPopVal);
bool rightBallDest = GetPartInputMults(ShipPartDestroy.EShipPartType.RIGHT_BALLOON, out rightBallRollMult, out rightBallPopVal);
float rudderYawMult = 0.0f;
GetPartInputMults(ShipPartDestroy.EShipPartType.RUDDER, out rudderYawMult, out tempNotUsed);
// Roll as if the only balloon left is pulling up
if (leftBallDest && !rightBallDest)
{
// Make the player still able to roll all the way
roll *= 1.5f;
// Right balloon pulling up, left popped
roll -= leftBallPopVal;
}
else if (!leftBallDest && rightBallDest)
{
// Make the player still able to roll all the way
roll *= 1.5f;
// Left balloon pulling up, right popped
roll += rightBallPopVal;
}
// Ship right on the XZ plane
Vector3 shipRightXZ = m_trans.forward;
shipRightXZ = Vector3.Normalize(Vector3.Cross(Vector3.up, shipRightXZ));
torque += handleMod * -pitch * reverseMult * shipRightXZ * pitchForce;
torque += handleMod * yaw * (1.0f - rudderYawMult) * reverseMult * Vector3.up * yawForce;
torque += handleMod * (-roll + -yaw * 0.25f) * (1.0f - leftBallRollMult - rightBallRollMult) * m_trans.forward * rollForce;
// Add all the torque forces together
m_myRigid.AddTorque(torque);
}