What are the default units in Avian? #939
-
|
I'd like to clarify what units does avian2d use to simulate dynamic bodies. I'm mostly confused about gravity here. The docs mention default gravitational acceleration to be 9.81$\frac{m}{s^2}$, but I think it might actually be in If so, then what is the purpose of defining the PIXELS_PER_METER constant? An additional question arises, what is the default mass unit? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Avian (and physics engines in general) don't really have specific physical units. The main thing is just that they should be dimensionally consistent with real-world physics, for example velocity is "distance units per time units", and mass is defined as "volume units times density units". Depending on the scale of the world, you could treat "distance units" as meters, or centimeters, or pixels; you just need to consider how this affects other units like mass, since volume of course depends on your chosen distance unit. In practice, I strongly recommend most games to use SI units and MKS (meters, kilograms, seconds) unless you're working at small or large enough scales where using meters would lead to very small or very large values. For example, a tiny car game might prefer that 1 unit = 1 cm, while a planet simulation might want astrological units. But for most games where object sizes are naturally expressed in meters, it is generally the most intuitive option from a physics perspective. The problem in 2D is that the default 2D camera assumes that 1 unit = 1 pixel, so if you're using meters, 1 meter = 1 pixel. This obviously isn't what you want for most games. You have roughly three options:
I would typically recommend (1) if you don't need pixels for gameplay reasons, and (3) otherwise. If you do pick (3), it's recommended to set the |
Beta Was this translation helpful? Give feedback.
Avian (and physics engines in general) don't really have specific physical units. The main thing is just that they should be dimensionally consistent with real-world physics, for example velocity is "distance units per time units", and mass is defined as "volume units times density units". Depending on the scale of the world, you could treat "distance units" as meters, or centimeters, or pixels; you just need to consider how this affects other units like mass, since volume of course depends on your chosen distance unit.
In practice, I strongly recommend most games to use SI units and MKS (meters, kilograms, seconds) unless you're working at small or large enough scales where using meters …