Log in

View Full Version : basic yet mysterious physics engines



BuzzKillington
07-04-2011, 11:11 AM
In racing games such as Gran Tourismo or even your basic java drag racing games like "Nitto 1320" cars can be modded and gear ratios adjusted all effecting how the car performs.

How does this work? What tells the game what mods make what difference and what ratios do what with the cars acceleration/speed? While in real life there is no set number, I find it hard to believe in a game there isn't some sort of algorithm that tells the game what works and what doesn't.

It's odd to me that something so complex can be added to very "basic" racing games. This is really blowing my mind. My head hurts.


:think:

mDust
07-04-2011, 11:27 AM
A mathematical formula can be devised to describe anything. I've seen attempts to discover the meaning of life that blow everyone's mind. There is definitely an equation that consists of every chemical, electrical and mechanical input and output for a vehicle...it would be incredibly complicated. It's complexity would scale with accuracy. Gear ratios would be a tiny part of it. You'd damn well better be a mechanical/automotive engineer, an inventor, or really really f***ing curious to have an excuse to figure any of it out. There are geniuses walking among us that routinely describe everyday, ordinary things with complex equations just for fun. I've seen it happen before and I don't pretend to understand it.:?

BuzzKillington
07-04-2011, 11:46 AM
But how are basic racing games getting ahold of this wonder of the universe!? It's driving me insane! I started writing it out but got nowhere.

Scenario:
4 gears. Each gear has a setting of 1-10. Does the game know the magic numbers that are best for that specific vehicle? Let's say they are 10-8-6-5. Is it a game of "Hot & Cold"? 4-3-2-1 COLD! Your car sucks, it's way off! 9-8-6-5. HOT! You're burning up! You're car's fast but not performing 100%.

Throw in different combinations of car modifications, aerodynamics, tire pressure, final drives, gear ratios to the 0.000 range and my head explodes. Is it the holy grail of scripts or are developers coming up with these rules on their own? I need to learn! lol

mDust
07-04-2011, 11:50 AM
Hell no game developers aren't coming up with this on their own...or at all. Car manufacturers and their race teams figure it out. They over-engineer every single part to optimize performance...to win. This is why any typical race car is generally several million dollars.

BuzzKillington
07-04-2011, 12:05 PM
but how are they converting this to game lingo? How does the game determine what numbers make the car perform better? In real life I understand the concept but in a game there's no way a basic free game can implement such complex stuff. There's gotta be a set "puzzle" if you will that is the hidden goal. Maybe they throw you off by allowing perfect shifts to last 100-500 rpms / .5-1.5seconds in motion. That's a huge window when you're talking drag racing. Shifting at the beginning of the perfect shifts can make a huge impact (for better or for worse) than if you were to shift at the end of the perfect shift window.

mDust
07-04-2011, 12:39 PM
The physics engine takes basic figures and plugs them into known equations to simulate gravity, impacts, explosions, and in this case various forces on a car. How much is accurate and how much is fudged depends on what the game developer felt was best for the game.

Some code ran that computed an 'efficiency value' and an if then statement determined 'how good' it was.

EDIT: Here (http://www.4lo.com/calc/geartable.htm)you go. It's for trucks, but the principle is the same. Certain gear ratios will yield more or less performance depending on tire size. The game designers likely used a more complicated but similar data set to determine car performance in game. Nested if then statements and algebra is a powerful thing.

Xpirate
07-04-2011, 01:51 PM
I made a very basic drag race game about ten years ago. The output was just a line of output at the DOS prompt that constantly updated with every execution step.

I used a parabolic function to determine torque based on RPM. It was very basic, but I eventually got it to where you had to correctly go through all the gears to get better times.

This is all I had documented in the code (I really, really should have taken better notes):

Formulas:
Torque = (RPM / 15.0) - ( (RPM * RPM) / 120000.0 ) + torqueChange;
This is the formula for an upside down parabola

HP = (Torque * RPM) / 5252.0;
5252.0 == conversion factor for torque to HP

Accel = (Torque * Gear * 4) / 109.0; Unit of feet/second^2
109.0 == mass of the car in slugs

MPH += 0.6818 * Accel * 0.01;
0.6818 == convert feet/second to MPH
0.01 == time interval in seconds

RPM = MPH * 11.2 * Gear * 4.0;
4.0 == rear axle ratio
11.2 == ???

Distance += MPH * 0.01467;
0.01467 == conversion for MPH, unit of feet
derived ???

BuzzKillington
07-04-2011, 10:42 PM
So with that formula it appears one couldn't actually calculate an ideal ratio. actually, it looks like the gears are pre-set, just the possibility to shift at ideal rpms. That's definitely part of the code I'm looking for but in this game it ranges from 1.000-5.000 and everything in between.

I wonder if I could just skip this mess and pay someone to reverse engineer an android game and automate the revs and shifting to eliminate human error while testing ratios. $250 bucks if anyone is interested.

NightrainSrt4
07-05-2011, 08:01 AM
The wiki (http://en.wikipedia.org/wiki/Gear_ratio) actually has a good set of information on this. All the equations shown can easily be turned into algorithms with variables.

Wiki:

For example, it is possible to determine the distance the car will travel for one revolution of the engine by dividing the circumference of the tire by the combined gear ratio of the transmission and differential.

d = c_t / (gr_t * gr_d)

It is possible to determine a car’s speed from the engine speed by multiplying the circumference of the tire by the engine speed and dividing by the combined gear ratio.

v_c = (c_t * v_e)(gr_t * gr_d)

It all HAS to be broken down into a set of mathematical equations, which themselves are easily converted into algorithms. Take for example we know the gear ratio of my car. I don't change my tires for anything larger, or smaller. If I am in 3rd gear, and going 3,000RPM, I already know my speed without having to look at the speedometer. All things equal, my speed will always stay the same with the same gear, the same gear ratio, and the same RPMs. Given all the data for a series of points, you could get a rough estimate of the equation just with the data from one car.

xr4man
07-05-2011, 08:45 AM
first off, i think the OP is over thinking it a bit too much. there isn't a magical combination of settings that makes a car perform better than anything else. it all comes down to the driver.

so there would be calculations for gravity, downforce, lateral forces, acceleration due to gear ratios, etc, etc. but all of that means nothing until you have a driver that can drive the way it's set.

for example, the very first porsche race car built by automobile union in germany in the 30's was virtually undrivable because of the placement of the engine in the back like today's porsches. so what the auto union team did was hire a motorcycle racer (someone who didn't have a clue how a race CAR was supposed to handle) and that dude took the "ill-handling" auto union car out and commenced to stomp all over mercedes and everyone else.

the point here is that the auto union car was very far from what was considered ideally setup, but once someone showed up that could drive it, those settings became ideal for that person.

i hope that helps to understand that there is no hot and cold settings for these games. only calculations as to how the setting effects the way a car handles.

BuzzKillington
07-05-2011, 11:59 AM
xr4, tell that to the race teams dropping millions of dollars on research and testing into their dragsters. lol

xr4man
07-05-2011, 12:17 PM
why? they already know that the settings for one driver may not work well for another driver.

yes there are "basic" adjustments that work better than others, but once you get the basics down, you still have to fine tune for the driver himself.

i'm not trying to say that you can go out and find someone that can race a car that has the adjustments totally out of whack, i'm saying that each driver will prefer to have their car handle differently, so therefore you can't just have a specific set of adjustments that works perfectly for everyone.

NightrainSrt4
07-05-2011, 02:19 PM
No, but you can calculate theoretical maximums when you take the driver out of the equation.

xr4man
07-05-2011, 02:47 PM
no car can do anything without the driver though. even with an AI you would have to fine tune the car for the "driver."

Diamon
07-05-2011, 04:18 PM
@xr4
This isn't about the driver or any preferences he/she/it might have. It's the theoretically most efficient way of driving the car. Your're of course right in that you need to find a driver or computer that can get as close as possible to that when its time to drive it.

dr.walrus
07-05-2011, 08:23 PM
The physics engine takes basic figures and plugs them into known equations to simulate gravity, impacts, explosions, and in this case various forces on a car. How much is accurate and how much is fudged depends on what the game developer felt was best for the game.

This, this, a billion times this.

Want to simulate physics? Get all your equations for Newtonian physics and simulate the in a computer environment. Want to make the game easier? Then add real world impossible values...

..For example, set the centre of gravity two metres under your car. Physically impossible, but in your simulation, your car can barely ever turtle unless its wedged.

Twigsoffury
07-06-2011, 02:11 AM
always remember.


A good driver in a Ford fiesta will beat a poor driver in a porsche around the track.


Anyone with a fat wallet can go fast in a straight line, but it takes talent to turn.

BuzzKillington
07-06-2011, 07:56 AM
The train is derailing! lol

mDust
07-06-2011, 09:32 AM
The train is derailing! lol

No, no. It's just going through a tunnel. Be patient, it'll come out the other end.

Konrad
07-06-2011, 01:36 PM
I've asked similar questions about flightsims. Is the software in your simulated F16 flight computer as advanced as the software in the real F16? More advanced? Simpler? How much overlap is there between the two?

mDust
07-07-2011, 12:18 PM
I've asked similar questions about flightsims. Is the software in your simulated F16 flight computer as advanced as the software in the real F16? More advanced? Simpler? How much overlap is there between the two?

The sim is much more basic. The simulator busies itself more with calculating physics, realistic models and landscapes, textures, and then rendering. I've never seen a simulator that generated a fuel leak in the left tank that caused a safety system to pump the leaking fuel into the good tank and adjust the ailerons to compensate for roll. If you had a simulator that could simulate everything that could possibly go wrong and the aircraft could automatically take corrective action when the real F16 could, then the simulator might be as advanced. I also think software tracking a target that it has generated itself is a bit easier than tracking real, physical targets.
Though it would be a bit less fun when you get disciplined for buzzing the tower while constantly ignoring ground instruction and find yourself simulating mopping the latrines after each mission.:D
Game developers cut corners...a lot. I can only hope that engineers designing a $30-50 million advanced fighting machine don't cut as many.

xr4man
07-07-2011, 01:28 PM
Though it would be a bit less fun when you get disciplined for buzzing the tower while constantly ignoring ground instruction and find yourself simulating mopping the latrines after each mission.:D
bwahahahaha

of course that might be a good idea to show kids there are always consequences for their actions.


Game developers cut corners...a lot. I can only hope that engineers designing a $30-50 million advanced fighting machine don't cut as many.

you'd be surprised at how many corners get cut.

basically the process is: make something cool as **** that the military will buy, then redesign it and make it as cheap as humanly possible.

xr4man
07-07-2011, 01:29 PM
hahaha, i didn't know there was a bad word filter set up here.

NightrainSrt4
07-07-2011, 01:37 PM
Physics / AI simulations are very expensive computationally if you don't simplify or fudge things.

Shoot, even the cellular automata approach I used for the water in my project could easily bring my system to its knees if I run it over a huge map. I have to narrow its scope to only calculating water mass/movement/propagation near the player. It is really enlightening how efficiently you have to program to try and get everything for even a simple game running in real time without any slowdowns. People that talk about games with sloppy or inefficient coding really don't know what sloppy or inefficient is. A single simple loop can drag everything down around it even if its running O(n) if n is sufficiently large.

Then you get into P vs. NP, computational complexity, etc. Many things can be modeled with algorithms and mathematics. But there are also many things that just can't be modeled on a CPU and run in any reasonable amount of time. We can try and write estimations, approximations, etc. but that is pretty much as close as we can get in a feasible amount of time.

Xpirate
07-07-2011, 10:11 PM
The one I made uses a 28 inch tire and a 4:1 rear axle ratio. Then the gear ratios are 4:1, 3:1, 1:1, and 1:1. You can determine the perfect RPM shift points by looking at torque vs speed vs each gear graphs.

You determine torque by the RPM that each speed and gear can correspond to. There will be a graph for each gear. The ideal shift point is where the graphs intersect. Depending on how you do the gear ratios, the ideal shift points could be different between each gear change. I can't find the spreadsheet I made all those years ago that did this.

The next thing to do is determine what gear ratios you can use to keep the RPM's in the higher torque regions as you go through the shift points. More graphs will need to be generated so you can see which ones have better intersect points and keep more area under the intersecting curves.

That drag race game could have a parabola for torque like mine did, or a simple linear function that goes up to the peak and down. I really doubt that it does something more complicated than that. The game developer probably added wind resistance to his.

My simulation did not work right until I added logic to make the clutch slip. I never got around to making tire slip logic work. I came up with a few theories on how I could make it work in my mind a few times but never put pen to paper.