Applying Impulses based on Body Mass

Topics: Developer Forum, User Forum
Apr 10, 2010 at 9:59 PM

Hi all,

For my game, each level will have a number of items that are interactive, in that they may be given a nudge, picked up and moved, etc.
I'm implementing the "nudge" behaviour, which is basically just applying an impulse to a body along the +ve or -ve X-axis, depending on which mouse button is pressed.

All my "nudgeable" objects go in a List, which is then iterated through and checked for mouse clicks. If one is detected, the impulse is applied to the appropriate body.

Now the deal is that I have different shaped/sized objects, which obviously have different masses (eg: a boulder is heavier than an empty crate). In this regard, I want to know what sorta Math formula I can use in calculating the impulses to be applied,
so that the object's mass is taken into account. In other words, a single left or right click on my boulder or crate should move them by the same amount, not make the boulder crawl and the crate fly a mile away.
I'm not too sure if what I've got's correct, and Math isn't one of my strong points either, so any help would be greatly appreciated.

This is basically what I'm doing at the moment:

// Calculate nudge impulse to be applied
float nudgeForce = 10.0f * body.Mass;
float propulsion = nudgeForce - (body.Mass / body.MomentOfInertia);
// Apply the impulse
body.ApplyImpulse(new Vector2(propulsion, 0.0f));

Seems to work better than just having a constant impulse, but I don't think its quite right yet, due to the fact that I multiply the body's mass with the constant force.
As a result, heavier objects get more of a push.
Sorry if this is a really noob question, but like I stated, am not too techy with Math & Physics.

Thanks for any help in advance. 


Apr 11, 2010 at 5:22 AM

In physics, an impulse is a Force applied for a amount of time.  The units for an impulse is kg*m/s (kg = weight in kilograms; m = meters; s = seconds). The first part of your calculations look fine (10m/s * body.Mass).  I'm pretty sure that would be correct if you applied that as an impulse.  Moment of inertia is for rotating objects, so you don't really need it here.

You know, you could also just set LinearVelocity to the velocity you want, then you don't have to worry about the proper calculations to get the proper final velocity.

Apr 11, 2010 at 5:52 AM

@ Ciph3rzer0:

Thanks for the reply. So you're basically saying that the (10.0f * body.Mass) formula should work on its own, right? But by using just that, doesn't it mean that heavier objects will get a much larger boost than lighter ones? Because it kinda looks like that currently, my boulder has a mass of 300 kg and the crate 
has one of 25 kg, so the boulder gets a much harder push and then moves a bit faster than the crate. Would there be a way to adjust the formula somehow so that they both appear to have been given the same boost?
'Cos it would look a bit strange, a big solid rock moving more and further distance than an empty little crate does, with just one click on each.

My main reason behind wanting to nail this is so that I don't have to go about manually defining the force amount for every single object that's nudgeable - it'd be a pain and not very good programming practice, I assume.

And yup, I could alter the LinearVelocity, but then keep in mind that the object would continue moving at that rate until something else came along and changed it, and that behaviour wouldn't be very realistic... 

Apr 11, 2010 at 6:30 PM

Well, it makes sense that the heavier object would get a larger push, it takes more force to push a a car at 10m/s than a baseball.  Do you have a linear drag in effect? Because that could cause the bolder to appear to move faster (the drag would slow it down more slowly, since it has more momentum).

From what I remember from physics, what I told you should be true.  I could be wrong though.

I thought if you set the linear velocity, that other forces (such as linear drag) would still affect it.  I've never set it directly though.