- 11,294
- Sweden
- eran0004
a simple yes would have been quicker yep i love carts and you cant beat a nasa one
Some clutches also have damper springs to soften the response, so I just wanted to be clear about what kind of spring I was talking about
a simple yes would have been quicker yep i love carts and you cant beat a nasa one
Some clutches also have damper springs to soften the response, so I just wanted to be clear about what kind of spring I was talking about
I have got so much info going in at the moment mate i am forgetting things i used to know. And getting things confused all the time.
I think 5 hours sleep a night since Christmas haven't helped. Well remember a few post's i was on about syncing the Hertz? well i used the wrong term again i used old arcade pcb timing as in hertz to monitor. I think you need something like deltatime in unity, it smooths everything out there's example script's and video in the link that explain's better than i could.
https://unity3d.com/learn/tutorials/modules/beginner/scripting/delta-time
Maybe you could use it in your blender simulation
I've found this as well, from the author of the car physics tutorial I'm using. The actual web site doesn't exist anymore, but fortunately it's still available through the internet archive.
http://web.archive.org/web/20050204163259/http://home.planet.nl/~monstrous/tutstab.html
Hopefully it will solve the issues.
That's full on, I glaze over at sites like that takes me a few hours to Google all the terms ☺. Driving sims are so demanding I take a step forward and 3 back it seem's.
Have you got your head around your bogging down yet or is it still a mystery ?
# constants
physics_time_step = 0.005 # sec, i.e. 200Hz
# you can tweak this for more accuracy (lower) or less CPU burden (higher)
# this has to be done every frame
dt = get_time_beween_last_frame_and_now()
psteps = floor(dt/physics_time_step) # find out how many physics steps we have to do
for i in range(psteps):
a = Force()/Mass() # calculate accelerations
alpha = Torque()/Inertia() # calculate angular accelerations
# do physics integration with small time steps
v += a * physics_time_step
p += v * physics_time_step
omega += alpha * physics_time_step
phi_rad += omega * physics_time_step
# now you have to do the last time step
last_step = dt - psteps * physics_time_step
a = Force()/Mass() # calculate accelerations
alpha = Torque()/Inertia() # calculate angular accelerations
v += a * last_step
p += v * last_step
omega += alpha * last_step
phi_rad += omage * last_step
# now apply the position changes and rotations
body.applyRotation(phi_rad)
body.applyTranslation(p)
That *Broing* sound was not expected.
#clutch release
if logic.car['clutchPressed'] == False and logic.car['clutch'] > 0:
x = logic.car['rpm']
y = logic.car['clutch_rpm']
if x > 2500:
if x > y+1000:
if x > 4000:
clutchtarget = 0
else:
k = -1/3000
m = 4/3
clutchtarget = k*x+m
cRelease = clutchDelta*0.5
else:
clutchtarget = 0
cRelease = clutchDelta
elif x > 800:
# y = a(x-h)**2+k
a = -1/1700**2
k = 1
clutchtarget = a*(x-800)**2+1
k = (clutchDelta-clutchDelta*0.1)/1700
m = clutchDelta-k*2500
cRelease = k*x+m
else:
clutchtarget = 1
cRelease = clutchDelta
if logic.car['clutch'] > clutchtarget:
logic.car['clutch'] -= cRelease
if logic.car['clutch'] < clutchtarget:
logic.car['clutch'] = clutchtarget
if logic.car['clutch'] > 1:
logic.car['clutch'] = 1
elif logic.car['clutch'] < 0:
logic.car['clutch'] = 0
I am thinking mere basics rather than re-invent Gran Turismo or some more proper sim racer. Something a bit funny I kind of realize is that I don't need meshes of tires and wheels to simulate tires going to work driving. Though, of course, it's a good bit awkward to have a vehicle that somehow sticks on the road without any tires (unless it's some anti-gravity ship of course). There is still a lot for me to learn. One of the reasons why I liked Godot is because I had better progress developing material than I have with Unity, Unreal Engine 4, Löve2D, or doing programming from scratch. If need be, I'll try to learn Python just to make a decent 3D racing game.
I do find this interesting.
I'd love to attempt even a numerical simulation, but I'd like to start much further upstream, like with atmospheric air, and fuel, and end up with traction at a contact patch... simulating the input variables at each stage, and not just something that simulates the output alone.
Sadly neither my grasp on the wide array of Physics necessary, and the scripting skills necessary are up to scratch.
Completed the landscape and added a speedometer and a tachometer. It's almost starting to look like a game.
Awesome work !
Any plans for VR ?
Assuming that the clutch is not slipping, the torque applied to the wheel is the same as the torque output of the differential. If you don’t have a differential then the wheel torque is the same as the output torque of the gearbox, divided by the number of powered wheels (and minus any frictional losses along the way). The output torque of the gearbox is the torque at the flywheel multiplied by the total gear ratio (gear ratio*final drive ratio).I'm mainly stumped on the topic of a transmission and getting my engine on some wheels, especially with your torque based approach. For my simulation I have chosen to use the friction based clutch system you proposed on the first page of the thread. I can't seem to wrap my head around how to calculate torque applied to my wheel in every frame - and would my initial clutch plate torque collected from my transmission (before calculating frictional forces) have anything to do with it?
It depends on what you want to do, I guess. A very simple vehicle model could just apply a force to the car that’s proportional to the power of the engine and inverse to the speed of the car:I'm also very confused on if using a torque based model is a good idea in the first place, as the transmission to my understanding is almost entirely rigid
Thanks! All is well The project is a few years old, not sure if I would use the exact same solutions now if I did it again, but I’ll be happy to help if you have any more questions!I hope that all is well.
Even though it's most likely been a while since you've touched this project, I also hope you're able to provide me with some much needed help. Thank you!
private void SimulateEngine()
{
flyInertia = 0.5f * flywheelMass * Mathf.Pow(flywheelRadius, 2);
engInertia = crankInertia + flyInertia;
Throttle = Mathf.Lerp(tMin,tMax,throttleInput);
if(RevCutOff<RPM && RPM < RevLimit)
spark = true;
else
spark = false;
if(spark)
{
float wotTorque = wotTorqueCurve.Evaluate(RPM);
float idleTorque = idleTorqueCurve.Evaluate(RPM);
torque = Mathf.Lerp(idleTorque, wotTorque, Mathf.Pow(throttleInput, RPM / (RevLimit * Throttle)));
}
else
{
torque = noSparkTorqueCurve.Evaluate(RPM);
}
float BHP = (torque * RPM) / 7120.91f;
flywheelAcc = (torque / engInertia) * (60 / (2 * Mathf.PI));
RPM += (flywheelAcc * Time.fixedDeltaTime);
//Sound system and debugging
currentRPM = RPM;
load = Mathf.Lerp(-1, 1, throttleInput);
Debug.Log($"Engine RPM: {RPM:F2}, Torque: {torque:F2}, BHP: {BHP:F2}");
}
wheelCollider.motorTorque = gearRatios[currentGear] * finalDriveRatio * torque; // torque = engine torque
Hey,
I hope you're doing well! I’ve been working on car simulation in Unity, and I’ve used your project as the starting point.
First, I created a torque curve generator that generates the torque curves:
View attachment 1423848View attachment 1423849View attachment 1423850
1) wotTorqueCurve
2) idleTorqueCurve
3) noSparkTorqueCurve
I've also got the engine with the flywheel working! Here’s the code and a video showing it in action:
C#:private void SimulateEngine() { flyInertia = 0.5f * flywheelMass * Mathf.Pow(flywheelRadius, 2); engInertia = crankInertia + flyInertia; Throttle = (tMax - tMin) * throttleInput + tMin; if(RevCutOff<RPM && RPM < RevLimit) spark = true; else spark = false; if(spark) { float wotTorque = wotTorqueCurve.Evaluate(currentRPM); float idleTorque = idleTorqueCurve.Evaluate(currentRPM); torque = Mathf.Lerp(idleTorque, wotTorque, Mathf.Pow(throttleInput, currentRPM / (RevLimit * Throttle))); } else { torque = noSparkTorqueCurve.Evaluate(currentRPM); } float BHP = (torque * RPM) / 7120.91f; flywheelAcc = (torque / engInertia) * (60 / (2 * Mathf.PI)); RPM += (flywheelAcc * Time.fixedDeltaTime); //Sound system and debugging currentRPM = RPM; if (throttleInput > 0) load = Mathf.Lerp(load, Mathf.Abs(throttleInput), throttleInput); else load = Mathf.Lerp(load, -1, 1-throttleInput); Debug.Log($"Engine RPM: {RPM:F2}, Torque: {torque:F2}, BHP: {BHP:F2}"); }
To me, the engine RPM seems alright, but I'm not entirely sure about the torque output.
Right now, I'm stuck on implementing the transmission. As you mentioned: "There are forces from the crankshaft acting on the transmission, and forces from the transmission acting on the crankshaft."
I’ve spent hours trying to solve this, but none of my attempts have worked so far.
I have all the necessary things like gear ratios.
Additionally, Unity has something called a Wheel Collider, which simulates wheels and uses torque to propel the vehicle. These colliders have properties like:
I assume the torque at the wheels should be set like this:
- motorTorque: used for propulsion
- brakeTorque: used for braking
- mass
- forwardFriction
- sidewaysFriction
- rpm
- rotationSpeed
This should result in the car moving forward, but there is no correlation between the engine and the transmission, so, as expected, the engine RPM doesn’t respond to the car’s movement.C#:wheelCollider.motorTorque = gearRatios[currentGear] * finalDriveRatio * torque; // torque = engine torque
I’m struggling to figure out how to properly blend the forces from the crankshaft with those from the transmission.
Any advice would be greatly appreciated!
Thanks for your awesome work on the simulation — it’s been super helpful for my project!