Best units of measurement in Unity

Quick simple question, I am about to try and work out calculations and stuff for my game (first person shooter) was was curious to know what units I should use in unity to make things easier, or if it makes no difference, for the following:

Bullet Speed:
Feet per second vs meters per second

Bullet Energy
Foot Pounds vs Joules

Bullet Mass
Grains vs grams vs kilograms?

I know computers being computers means that I can put it in however I like then when I create the script or whatever I can put in an equation to convert it to whatever unit I want, but if the physics engine or something already uses a certain unit I might as well just go direct to that unit and store my data as the unit it uses.

Thanks.

The defaults are set up for 1 unit = 1 meter. The physics engine does best (due to floating point limitations) when objects have a mass of around 1.0 - 10.0.

–Eric

1 Like

Thanks Eric,

When you apply force to a mass in unity, you dont happen to know how its attempting to be calculated do you? (ie, is it applying 1000 joules of energy to a 1kg object?)

Well, the mass is down to you. Use kilograms as far as possible. When you apply forces you’re applying Newtons. A Joule is a unit of energy.

1 Like

Oh cool - I didn’t know that the force roughly translates into newtons. Nice info. :slight_smile:

Thanks,

Is there any kind of formula I can do to get newtons into joules for a rifle, ie the projectile is .0104kg, I want it to leave the rifle at 850 meters a second, thereby having 3757 joules of energy? I could apply newtons over the barrel length but muzzle velocity x bullet mass are independent of barrel length so im a little confused or is it just a matter of trial and error till I get it roughly correct?

A force F moving m metres will do work J = F*m. Since force is mass times acceleration, you can say J = M * a * m, where a is the acceleration and M is the mass. So, I guess you can work out the acceleration based on barrel length and exit velocity. I doubt that the exit velocity is independent of barrel length, surely the bullet takes some time to accelerate up to 850 m/s?

1 Like

The acceleration is not constant. Bullet is pushed by gas rapidly increasing its volume and therefore decreasing its pressure.

It is not.

Like one fixupdate? :slight_smile:

Why anybody would like to do such simulation with PhysX?

1 Like

Yeah, I wouldn’t simulate bullets with the built-in physics. I’d use a raycast to sweep the (approximated) motion of the bullet each frame, and do some calculations each frame to see how far it moved and in what direction.

Physics libraries like PhysX don’t do too well with rapidly moving bodies, and a bullet is most certainly one of those.

1 Like

Yeah, I abandoned the physics approach, due to the bullet flying through my targets :slight_smile: .

I found this really awesome youtube video:

which includes a link to be able to download the project, which is helping me a lot.

Now I am just busy getting frustrated with different things, ie, unity seeming not to update my variables like It should.

eg, I had rate of fire at cooldown = 10, Time.Deltatime() * 1 bla bla which worked fine, but then I had it set at
int ROF = 600;
cooldown = ROF/60;

which you will note should work exactly the same, but it wouldn’t it kept firing as fast as possible.

Then I went back and fixed cooldown, but at a slower speed (.5 rounds per second), and then it went at a slower speed, as expected, then I went and put in the same cooldown = ROF/60 again, so the script was exactly as it was before, but this time it kept shooting at the slower speed, not as fast as possible like before.

I tried putting some debug code in but as it seems to be using some kind of cached script instead of the one im working on the debug code wont work.

So… yeah… no idea whats going on.

Maybe im doing something silly, maybe its bugged.

Nope, turns out im a retard,

I had
if (bla bla bla); <---- see? semi colon, shouldn’t be there…
{
shooting stuff
}

2 Likes

wow, no-one else here would ever make that sort of mistake
:sweat_smile:

1 Like