Hello, So today I thought I would give vehicle systems a try. I wanted to make my system as realistic as possible so I spent hours doing research on how engines work and one thing that struck me as wierd in the unity engine was how the Wheel Torque worked (You aren’t allowed to change the RPM and it seems to just use the torque as speed) So I made this code anyway :
#pragma strict
//Wheels//
var FRWheel : WheelCollider;
var FLWheel : WheelCollider;
var BRWheel : WheelCollider;
var BLWheel : WheelCollider;
//Torque//
var MaxTorque : float = 50;
private var CurrentTourque : float;
//EngineStats//
var EngineForceN : float;
var Cylinders : float;
var EngineSpeed : float;
var Bore : float;
var Stroke : float;
var EngineTorque : float;
var Torque : float;
var CID : float;
var RPM : float;
var HorsePower : float;
var Liters : float;
var HorsePowerPerLiter : float;
var HorsePowerOutputPCC : float;
var HorsePowerOutput : float;
var PoundsFeetPM : float;
var CC : float;
var HeadFlow : float;
var PumpOutFlowGPM : float;
//Drive//
var BackWheelDrive : boolean = true;
//Gears//
var Gears : float[];
private var CurrentGear : float;
//Controls//
private var HandBrake : boolean = false;
var CenterOfMass : GameObject;
function Start () {
CID = ((Bore * Bore) * 0.7854 * Stroke * Cylinders);
PumpOutFlowGPM = RPM * CID / 231;
HorsePowerPerLiter = HorsePower / Liters;
HorsePowerOutputPCC = HorsePowerPerLiter / 1000;
HorsePowerOutput = CC * HorsePowerOutputPCC;
PoundsFeetPM = HorsePowerOutput * 33000;
EngineTorque = 5252 * HorsePowerOutput / RPM;
Debug.Log(EngineTorque);
CurrentTourque = 0;
CurrentGear = 1;
}
function FixedUpdate () {
rigidbody.centerOfMass = CenterOfMass.transform.localPosition;
CurrentTourque = (EngineTorque / Gears[CurrentGear]);
if (BackWheelDrive == true){
BRWheel.motorTorque = CurrentTourque;
BLWheel.motorTorque = CurrentTourque;
}else {
FRWheel.motorTorque = CurrentTourque;
FLWheel.motorTorque = CurrentTourque;
}
}
So according to many sources the way torque is calculated is t = 5252 * HP / RPM But this doesn’t seem right to me as this means the lower RPM i give my car the faster it will go I was wondering if someone could see the flaw in my logic.
Thanks for the help - Aiden