Collision glitches

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
nug700
Posts: 9
Joined: Sat Dec 03, 2016 2:34 am

Collision glitches

Post by nug700 »

So I'm using the code below to directly set the linear velocity and a angular velocity of my tank using the user input. The other tank's linear velocity and a angular velocity are being set to zero every frame (as no input is being given).

Code: Select all

float mov = Input.GetAxis("Vertical");
float rot = Input.GetAxis("Horizontal");
        
float movement = mov * (m_Speed);
float aMove = rot * m_TurnSpeed;
        
bp.Vector3 BPdir = MultiplyQuaternion(BPtankHull.Orientation, new bp.Vector3(0, 0, 1)); // gets transform forward
BPtankHull.LinearVelocity = new bp.Vector3(BPdir.X * movement, BPtankHull.LinearVelocity.Y, BPdir.Z * movement );
BPtankHull.AngularVelocity = new bp.Vector3(0, (rot * m_TurnSpeed), 0);

space.Update(frameDelta);
It works for the most part, but for some reason in a lot of cases, the objects glitch and pass through each other:
https://www.dropbox.com/s/blmg8miftqs56 ... s.mp4?dl=0


I'm using a convex hull for both of the objects, which is set to a convex version of the mesh.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision glitches

Post by Norbo »

There's a lot of very nonphysical behavior going on there which could not be reasonably generated by any control scheme operating on the velocity level alone.

It looks like the graphics do not match the physics representation. Maybe the graphical position is anchored on the plane, and the orientation is forced to be yaw-only. When the other tank's orientation seems to rapidly flip around, I suspect it's actually lying on its side or something and the interpreted graphical orientation is flopping around a discontinuity. As for driving through the other tank and obstacles, the tank might actually be flying around in the air.

If you directly visualize the physics position and orientation without any reinterpretation, I suspect the simulation will look much, much different.
nug700
Posts: 9
Joined: Sat Dec 03, 2016 2:34 am

Re: Collision glitches

Post by nug700 »

Thanks for pointing that out to me. I was doing both of those things, and when I set the position and orientation directly, it does show them getting thrown in the air. I have added these lines to provide a quick fix, but would like to know how this would be done properly with constraints (I can't seem to find some that simply constrain the position on a given axis).

Code: Select all

BPtankHull.Orientation = EulerToQuat(new bp.Vector3(0, QuatToEuler(BPtankHull.Orientation).y, 0));
BPtankHull.Position = new bp.Vector3(BPtankHull.Position.X, 0.66f, BPtankHull.Position.Z); 
I'd also like to know if there is an easy way to get the half height of a ConvexHull.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision glitches

Post by Norbo »

For the linear component:
The PointOnPlaneJoint would work. Just make connection A null so that the plane is attached to the world space rather than another entity.

A cheaper option would be to always set the y component of the tank's linear velocity to 0 and then set the position directly to be exactly where you want. Changing the position is nonphysical, but so long as the teleportation distance isn't too significant, it generally still works okay. Setting the y velocity to 0 avoids most divergence.

For the angular component:
To absolutely lock orientation to be yaw only, you could set the first and third rows of the entity.LocalInertiaTensorInverse to 0, like so:

Code: Select all

                    var locked = entity.LocalInertiaTensorInverse;
                    locked.Right = new Vector3();
                    locked.Forward = new Vector3();
                    entity.LocalInertiaTensorInverse = locked;
That effectively makes the inertia around those two local axes infinite, which means no dynamic force can make the angular velocity change around those local axes.

For a softer approach, you could use a SwingLimit. You can then configure the SwingLimit's softness to your liking. There's also the option of just changing the angular velocity when the entity's up vector diverges from world up. That would be cheaper than a full constraint.

For a convex hull's half height, you could take the ConvexHullShape and call its GetBoundingBox, or call GetLocalExtremePoint along (0,1,0) and (0,-1,0).
Post Reply