Help With Car Engine Torque Logic

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 :open_mouth: I was wondering if someone could see the flaw in my logic.

Thanks for the help - Aiden

The way I understand it, horsepower if the force that the engine gives out into the drivign system, and torque is the force needed to turn the system, as in more torque the heavier a cargo the system can haul, the higher the horsepower the more energy the system has to spare.

The wya unity handles this does seem right with this in mind as it uses the physics engine to handle it after applying the force, and the slower the engine turns the more energy is used per turn. So the lower your RPM the slower you go, but the more power there is within the system to move the mass of the vehicle.

Disclaimer: i may be wrong

Thanks for the help, I tweaked the logic in the script, I guess the thing that I didn’t account for is that the RPM changes. :stuck_out_tongue:

Glad to help!