Tweaking applyImpulse

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Tweaking applyImpulse

Post by imtrobin »

Hi I'm applying a applyImpulse to a dynamic entity, and I noticed the origin of the impulse seems to affect the impulse strength. I thought it was just the direction magnitude.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Tweaking applyImpulse

Post by Norbo »

The direction's magnitude does indeed specify the strength of the impulse.

However, when an impulse is applied off of the center of mass, there is a torque component. This torque component varies depending on the application location. Specifically, the angular impulse applied for an off-center force is R x ForceVector, where R is the vector offset from the center of mass to the point, x represents the cross product, and ForceVector is the direction with magnitude.

For example, in the below picture with two equal-magnitude impulses A and B, impulse B is further away from the center of mass than impulse A. The resulting torque from impulse B will be greater.
Attachments
impulsesexample.jpg
impulsesexample.jpg (16.89 KiB) Viewed 9473 times
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Tweaking applyImpulse

Post by imtrobin »

I see. Thanks. What would be the best way to tweak it with the mass so things falls naturally. Say I have a tank, the box size is 13mx24mx22, and say I want titanmium (density=4.5), so my mass value should be = 30.888? With gravity -9.8, it seems to fall rather slowly through the air when I apply an linearimpulse and angularimpulse.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Tweaking applyImpulse

Post by Norbo »

There is no air resistance (think of it as a vacuum), so mass and density have no effect on the falling speed. What you're observing is probably just a side effect of your tank being so large relative to the gravitational acceleration.

Your tank is, in real-life terms, the size of a building. Imagine what a building flying through the air might look like under earth-like gravity. Compare it to what a small toy car looks like when it flies through the air. Both objects accelerate due to gravity at the same rate regardless of their mass, but the building appears to cover far less distance relative to its own size in the same amount of time.

If you increase the gravity to match the size of your world, things will appear to fall at the appropriate speed. For example, if you wanted your tank to be, in real life terms, about the size of a normal tank (around 5x4x8 in meters or so), you'd need to scale down your tank by about 3x. So, instead of scaling down your entire world, you can scale up your gravity by about 3x to achieve a similar effect. Try (0,-30,0) and see how it feels.

A general note to others reading this: Having excessively large world can cause problems with collision detection and stability. Staying on the same order of magnitude of the real world where 1 unit = 1 meter is a good idea. Scaling up the gravity to bridge a relatively small gap in sizes (like 3x) should work, but try not to go too far.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Tweaking applyImpulse

Post by imtrobin »

We scaled the units because midaway we found the units too small compared to the world. I tried setting the gravity 3x, what it did was to prevent the entity from going up but the downwards is still the same.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Tweaking applyImpulse

Post by Norbo »

Are you continually applying an impulse upwards? If so, that will counteract gravity. Regardless of the impulse's origin, the full magnitude of the impulse will still be applied to the linear momentum. If you want only a torque, consider using applyAngularImpulse instead. If you want an 'explosion' effect, apply a single large impulse at the beginning to set the entity in motion and then let it fall unopposed.

Otherwise, make sure there isn't any linear damping on the entity or other things that might slow it down.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Tweaking applyImpulse

Post by imtrobin »

No, only once. I'm actually applyAngularImpulse and applyLinearImpulse directly. I didn't set any linear damping though.
Last edited by imtrobin on Wed Aug 05, 2009 5:58 pm, edited 1 time in total.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Tweaking applyImpulse

Post by Norbo »

And increasing the gravity has no apparent effect on the fall speed?
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Tweaking applyImpulse

Post by imtrobin »

Not as much as it seems. I have video here, applyImpulse 0.5,20,0.5, position at the tank centre.

http://envisagereality.com/downloads/te ... mpulse.avi

Setting linear velocity, angular is 1,0,0, linear velocity is 1,-1,1 as starting

angularImpulse.X += (float) Global.RandomNumberGenerator.NextDouble ();
angularImpulse.Y += (float) Global.RandomNumberGenerator.NextDouble ();
angularImpulse.Z += (float) Global.RandomNumberGenerator.NextDouble ();
angularImpulse *= 70;

bepuPhysicsComponent.Entity.applyAngularImpulse (angularImpulse);

linearImpulse.Y += 20f; // add upwards

bepuPhysicsComponent.Entity.applyLinearImpulse (linearImpulse);

http://envisagereality.com/downloads/te ... locity.avi

Gravity is 0,-40,0, mass is 0.3, box size is 22.5,13.5,24
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Tweaking applyImpulse

Post by Norbo »

What happens if you set gravity to something significantly higher, like -100? If there is no visible change, it seems like the gravity is being set back to -9.81 somewhere else in the program.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Tweaking applyImpulse

Post by imtrobin »

The tank just flies lower but the speed of falling looks not much different. I search for .gravity, there's only one place the sets it.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Tweaking applyImpulse

Post by Norbo »

That sounds like the expected behavior. If you want overall higher velocities, you need to increase both the initial impulse and the gravity. Check the attached image for some example combinations of gravity, initial velocity, the maximum height achieved, and the time spent going up and down in total.

Keep in mind that anything near the size of a tank won't fall like a toy car in real life; a tank blown into the air would look like it was in slow-motion in comparison.
Attachments
heightvstime.jpg
heightvstime.jpg (58.81 KiB) Viewed 9427 times
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Tweaking applyImpulse

Post by imtrobin »

I understand but surely we can make it behave like a toy car by adjusting the forces and torque, no?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Tweaking applyImpulse

Post by Norbo »

Yes, by increasing both the gravity and the initial impulse, the entity will cover more distance, faster- similar to a toy car. Consider the last graph in the set in my previous post- it still has a flight time of 4 seconds, like the first graph, but reaches a higher maximum height and the velocities at the beginning and end are higher.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Tweaking applyImpulse

Post by imtrobin »

i had to set the gravity to -200 for it look like a toy car.
Post Reply