Maarten Baert's website

Game Maker / C++ projects

Home Model Creator ExtremePhysics Game Maker DLLs SimpleScreenRecorder AlterPCB Quadcopters   Recent comments Search

Last modified: Sun, 11 Mar 2012

Unit systems

A question I've heard a few times now is 'what units does ExtremePhysics use'.

ExtremePhysics can use any unit system as long as it's consistent. SI units (meter, kilogram, second) are fine, but (pixel, kilogram, second) of (pixel, kilogram, step) works just as well. You just have to remember to be consistent: if you use (pixel, kilogram, step), the unit of speed is pixels per step, the unit of density is kilogram per square pixel, the unit of force is kilogram times pixel per step squared, ...

The units for distance, mass and time are the base units, you can convert any other unit you will need to a combination of those. You can find the full list for SI units here.

If you want to make the game as realistic as possible (e.g. using standard gravity, 9.81 m/s2), it's probably easier to use (meter, kilogram, second) and remember that (e.g.) meter = 50 pixels and second = 30 steps. In this case you should set 'timestep' to 1/30 with ep_world_settings. You also have to find a way to scale everything, either by using views, or manually with draw_sprite_ext (ep_debugdraw_set_transformation can also help). If you don't really care, (pixel, kilogram, step) is probably better for you.

Yes, you can also use inches, feet, miles, pounds, ... as long as you're consistent. However, for numerical reasons it's not a good idea to use units that are very small or very large compared to the thing you're simulating. So don't use meters if you're simulating the solar system. As a rule of thumb, if any of your numbers is greater than 10000 or less than 0.0001, you're probably using the wrong unit.



Comment #1: Thu, 8 Mar 2012, 20:06 (GMT+1, DST)


Well that's all good, but even with that information I'm unable to set it to react like reality.

I've made a constant called GRAVITY and set it to 9.81 (I suspect that of being in pixels per second² at base, so I also tried 313.6 pixels per second²)
I've made a 32x32 cube and gave it Fe's density (7.874 but is it per pixel?)
I put my timestep to 1/30 (1/30th of a second per simulation step right?)

The questions should be straight forward:
- Is the gravity interpreted in pixels per step?
- Is the density interpreted in grams per pixel?
- Is the timestep interpreted in seconds per step?

Putting the following values made it look somewhat realistic:
GRAVITY = 0.3065625 (9.81/32 px/s²)
Density = 7874 (kg/m³)
Timestep = 1

Last modified: Thu, 8 Mar 2012, 20:34 (GMT+1, DST)

Maarten Baert


Comment #2: Sun, 11 Mar 2012, 19:52 (GMT+1, DST)


@Dark_master4: You missed the scaling part. Unless 1 pixel in your game equals 1 meter, you have to find a way to scale everything. You could use views for that, or do it manually with draw_sprite_ext.

If you want to avoid that, just stick with (pixel, kilogram, step) and convert all your values to these units. Let's say in your game 50 pixels = 1 meter and 30 steps = 1 second.

9.81 m/s2 = 9.81 * 50 / 302 px/step2 = 0.545 px/step2

7.874 kg/dm3 = 7874 kg/m3
Note that this is 3D density, you have to multiply it with the thickness of the objects (in m) to get a 2D density. Let's say the thickness is 10 cm = 0.1 m.
7874 * 0.1 kg/m2 = 7874 * 0.1 / 502 kg/px2 = 0.315 kg/px2


Comment #3: Tue, 13 Mar 2012, 23:15 (GMT+1, DST)


Got it. Very helpful.

Write a comment