2 Questions about smashers and 2d physics

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Googoobachoo
Posts: 1
Joined: Sun Mar 04, 2012 12:36 pm

2 Questions about smashers and 2d physics

Post by Googoobachoo »

Hello,

i have a two part question about your most excellent physics engine :) which i use in my 2d-scroller:

1. In my game i have a couple of cliche smashers. What is the best way to detect if my ship is smashed? Is there a way to find out how much pressure is effected on an entity? Or should i check if the ship has contacts with both the smasher and the wall? My guess is that the latter won't work everytime and the ship gets catapulted away (which is what happens right now)., Can you suggest a better way?
Image

2. To achieve 2d I set position, and linear velocity to the XY plane which works flawlessly so far.
I also attempt to limit the rotation by zeroing the second column of the LocalInertiaTensorInverse and setting AnguilarVelocity like this:

Code: Select all

            Vector3 angVel = Vector3.Zero;
            angVel += new Vector3(0, 0, TurnThruster * TurnSpeed);
            Entity.AngularVelocity += angVel;
which works most of the time.
However, sometimes when flying into an opening door or hitting an enemy the ship is still rotated and points to the back or front:
Image
Do I have to zero the LocalInertiaTensorInverse every frame? I guess there is still some angular momentum coming from an off-center contact or something? Is there a way to prevent this?


Thanks for taking the time to read my questions!

Best Regards,
Christian
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: 2 Questions about smashers and 2d physics

Post by Norbo »

1. In my game i have a couple of cliche smashers. What is the best way to detect if my ship is smashed? Is there a way to find out how much pressure is effected on an entity? Or should i check if the ship has contacts with both the smasher and the wall? My guess is that the latter won't work everytime and the ship gets catapulted away (which is what happens right now)., Can you suggest a better way?
Checking for contacts with the smasher and a wall would work, but it does rely on classifying things as smashers and walls which could be a bit tedious.

The entity.CollisionInformation.Pairs.Contacts[j].NormalForce (NormalImpulse in v1.2) contains the impulse applied. An object being crushed by kinematic objects will have some very high associated normal impulses, making this a good option.

Do I have to zero the LocalInertiaTensorInverse every frame? I guess there is still some angular momentum coming from an off-center contact or something? Is there a way to prevent this?

It does not need to be set repeatedly. 3D has 3 angular degrees of freedom. 2D has 1 angular degree of freedom. By setting only one row of the LocalInertiaTensorInverse to zeroes, two angular degrees of freedom are still free. This allows the object to rotate into invalid configurations. To fix this, set two rows of the LocalInertiaTensorInverse to zeroes.
Post Reply