Custom collision response solving [v1]

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
janbo
Posts: 2
Joined: Thu May 28, 2020 5:15 am

Custom collision response solving [v1]

Post by janbo » Thu May 28, 2020 4:39 pm

Hello Norbo

I am new at BEPUPhysics but I have to say a very cool engine!

My experience:
I don't have much experience with Physics Engine.
I have been playing around with BEPUPhysics in my free time in the evenings for the last 3-4 weeks.

---

My question about BEPU v1:

When I use dynamic objects and they collide, the impulse/impact is very strong and the object push and change the velocity of each other.

is there a good possibility in BEPUPhysics that in a collision the objects do not give an impulse to each other just simply stop moveing (blocked) if an object block the way of the velocity. Stop/block without overlapping each other.

i have tried to visualize my idea... hop it helps to understand it better :)

Image

I have written the following code lines once for testing purposes but it not realy works as expected.
What is the best way to solve collisions in a custom way in BEPU v1? or with zero pushing/impules?

Code: Select all

var position =  Converter.Convert(transform.position); // convert Unity Vector3 to BEPU Vector3

var entity = new Box(position, 1, 1, 1, 1);
entity.LinearVelocity = Vector3.Zero;
entity.LinearDamping = 0.1;
entity.LocalInertiaTensor = new Matrix3x3(0, 0, 0 ,0, 0, 0, 0, 0, 0);
entity.CollisionInformation.CollisionRules.Personal = CollisionRule.NoSolver;

var events = entity.CollisionInformation.Events;
events.CreatingContact += (sender, other, pair, contact) =>
{
    var velocityDirection = Vector3.Normalize(sender.entity.LinearVelocity);
    var pos = -velocityDirection * contact.PenetrationDepth;

    sender.entity.Position += pos;
    sender.entity.LinearVelocity = Vector3.Zero;
};

---

Why v1:
I need a physics simulation which is cross platform/machine deterministic.
I found https://github.com/sam-vdp/bepuphysics1int. which replaces float with fixed-point integer math in BEPU v1.

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

Re: Custom collision response solving [v1]

Post by Norbo » Thu May 28, 2020 9:53 pm

I would recommend against modifying velocities in the CreatingContact event handler. While you're presumably only using one thread to guarantee determinism in v1 so it shouldn't cause a race condition now, it may help avoid future confusion or bugs if it's in a safer location. Consider enumerating contacts of the relevant objects outside of active processing- for example, in the Space.NarrowPhase.Finishing event.

As for the collision response, since this is a physically inconsistent behavior, there's going to be some arbitrary hackiness involved. The core requirement for any collision-ish solution is that objects don't overlap, so penetrating velocity along any contact normal between the objects must not be positive.

For the moving-vs-stationary case, it's pretty simple- all penetrating velocity along the contact normal is removed from the moving body. Ignoring signs to avoid having to go look conventions up and ignoring angular velocity, it would be something like:

Code: Select all

newVelocityA = velocityA - contactNormal * Vector3.Dot(velocityB - velocityA, contactNormal)
For the moving-vs-moving case, some arbitrary decisions must be made. Suppose they're moving at different speeds. Do they both still just stop? What if they're moving in the same direction, but one is slower? Does the one that runs into the backside of the other stop, and the other keeps going? What if one of the objects has 100x more mass, does that affect the desired result? The end math of subtracting out penetrating velocity along the contact normal is the same, it's just an arbitrary decision of how much velocity you take from which entity.

janbo
Posts: 2
Joined: Thu May 28, 2020 5:15 am

Re: Custom collision response solving [v1]

Post by janbo » Fri May 29, 2020 4:32 am

Thank you Norbo for your quick reply.

I will try to achieve my desired behaviour with your advice.

And thanks for the good questions at the end, that is very helpful!

Post Reply