🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Physics objects building momentum when hanging over edge

Started by
6 comments, last by LorenzoGatti 3 years, 8 months ago

Hey there!

I'm trying to make a simple 3D physics engine. Everything is working pretty well, except for this one problem I just can't figure out: when objects hang over the edge of another object even slightly they will build momentum until they eventually slide off:

The cause is pretty simple. In the example the box has physics enabled, while the platform is static. When the box lands on the center of the platform, it will generate the following normal and contacts:

Each of the contacts will generate angular velocity (as shown by the arrows). Since both contacts are equal distance away from the center of mass, their torques are exactly opposite and cancel each other out. However, when an objects hangs over an edge, the following happens:

The right contact is now closes to the center of mass than the left one, meaning it creates less torque. The total angular velocity therefor becomes non-zero and the box will rotate to the right, and the collision normal along with it:

(rotation exaggerated)

The box will be pushed out along the collision normal, causing it to build momentum to the right and eventually slide of.

This obviously isn't supposed to happen, but I don't know how to fix this. What am I missing? My code is a mess right now, so I'm kind of afraid to share it, but it can be found here.

Thanks for reading and have a nice day!

(Note: I made a post about this same problem a couple of days ago. However, I now know more about the specifics of the problem, which has caused my question to change.)

Advertisement

The contact force acting on the box should never exceed the force with which the box is pressing against the platform, which in this case comes from gravity. So, you are probably either not calculating the force of the box pressing on the platform correctly, or you're not applying it correctly when calculating the contact force. The right contact point bears more weight than the left contact point, so the box presses with more force on the right contact point than on the left contact point.

Sorry, I don't understand. Should the box not rotate into the platform (like in the third picture), or should that rotation not cause sliding? After it rotates inside, the box is pushed out along the new (rotated) collision normal and lands back down, after which it is just like the second picture but a little to the right. This cycle repeats itself until it slides off.

Assuming that the box has no initial velocity, the contact force pushing upward should perfectly cancel the downward force of gravity, for a net force of 0. So the box should not rotate.

I believe his whole concept is wrong, contact point is one extreme case that almost never happens.

What i would go for is (look at second img)to divide, shape into two boxes in this case cause theres nonedge-collision (no collision to the edge at all, dont blame me for nameless naming), for the weight balance here knowing center of gravity of the full shape i would calculate the resulting force (weight) acting on full shape by subtracting one shapes weight from another to see if the torque applies but its not as easy at it sounds and do require, checking whenever one of connected shapes lie within a rest, without it left shape will continousely try to rotate to the left whole body (which is true by the way), float inprecission should be maintained too, not mentioning friction, and thrird law of newtonian dynamics, which should nake box bounce back, but yeah no one should even crack his head that much

i'm not sure if i understood your problem well, but it seems to me that it is your collision detection and response which is the problem.

  • so we have two objects: box and plane
  • collision detection is simple:
    box to plane intersection = collided points on plane. Find these points on the plane.
    Then create a collision vector:
    cv = intersection point - box point
    Then see how far your box has gone into your plane:
    cl = cv.length( ) ( so if cl is 0 that means there was no intrusion of your box into the plane )
    Then create the collision response direction:
    cd = cv.normalise( )
  • now u have cl and cd, you can respond in various ways, one of which could be:
    new box point position = box point + cd * your-physics-settings::getCollisionResponseForceScalar( );
    this scalar could be a float (like 9.81) that says how much force to apply to the response, you may have to tweak this scalar to get the right feel for your engine system;
    Then you can LERP between box point and new box point using your engine's delta time in update(float deltatime);
    You can also apply speed of this response, turbulence, friction etc… and etc…

I have ooooverly simplified this, but this should give u an idea… hope this helps

That's it … all the best ?

Another point of view: rotation can only happen if there is a net torque. There shouldn't be any net torque, even if the box hangs beyond the edge of the table: the shorter distance from the barycenter is compensated by a greater force (a larger portion of the weight of the box).

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement