(Retitled) 2D ball collision and sliding (I am aware it is a repeated subject)

Started by
15 comments, last by jacksaccountongamedev 20 years ago
if you want pure sliding, you just set the friciton and drag to 0.

so it just becomes

V -= (1.0f + elasticity) * Vn;

not sure what you want exactly though

Everything is better with Metal.

Advertisement
Just a remark on the normal:

If we have a circle exactly touching a line, then there is only one point which they both have in common.
The circle should know in which direction to reflect, despite the point by itself can not define a normal! The circle doesn''t know the other points of the line, only the colliding one.

So: the normal used to calculate the reflection vector is circle-center -> collision point or something like that. (think about a circle colliding off a point and see the line as a bunch of points)

Am I right?

You don''t have to check whether the circle hits an end point or not.
Ooops... I'm not being very clear am I?
(Hope this helps)
What I mean is that eventually the ball is going to be bouncing so low that gravity will cause the ball to collide with the surface every frame . The result is that the ball stops dead:



The diagram shows the simplified path of the ball as it travels up a sloped surface. The ball ends up virtually on the ground and gravity has the effect of locking the ball into position on the surface. It certainly looks odd when the ball is bouncing down a slope, only to stop dead when it no longer bounces high enough to get off the ground. No matter how I handle reflecting the velocity after a collision the ball is always going to face this problem.

The system works like such:

ball velocity += gravity
Sweep test ball position to ball position plus velocity - note that the swept test does not take gravity into account; it acts as if the ball moved directly from on position to the other
If collision occurred, move to the point of intersection - balls original velocity sized to 0.01 (and calculate new velocity)
If not: ball position += ball velocity

What am I doing wrong here? (Ensuring that the ball’s velocity does not fall beneath a certain value does not work)

[edited by - jack_1313 on April 1, 2004 2:00:57 AM]
The reflective model is mainly a hack, and it's not good to base a physics model upon it. It fine for things like camera movement, character movement, and simple physics, but it's in no way a substitute for rigid body dynamics, in the magnitude you want to do. Even for a simple ball rolling down the slope, you'll need some major changes. Not mathematically hard, but the algorithm will change significantly.

OK, now I've got my brain in gear, let's talk

in general, there are three stages/states in a collision. Impact, contact, separation. That's when the contact velocity (V * N) is vn < 0.0f, vn = 0.0f, vn > 0.0f.

Each state reacts differently from a collision. So, if when the ball enters the contact state (it's supposed to roll), you can catch it and do a diferent physical model than when it's colliding. That's one part of the problem.

the more important flaw of the algorithm, is that using the regular reflective model, you never consider the contact velocity, only the ball's linear velocity. Imagine the ball being a tyre on a car. it's like having the brakes locked so the tyre/ball never rotates. you'll see that the tyre will basically skid and comes quickly to a halt.

if the ball is allowed to roll, then it's a different story. The contact velocity will be 0.0f (the tyre will roll freely), so the friction force will be minimal, and the tyre/ball will just roll down the slope like you want.

so, you need to consider some more advanced physics, with the ball having an angular velocity as well as a linear velocity. That involves considering the inertia of the ball, and applying contact forces. But that will allow you to do a lot more realistic stuff though. You can probably hack it, but I would think it's more work than actually doing the proper stuff. It's not that hard. as per usual, you have a basic rigid body physics demo Cube on plane, or in 2D, a more recent physics demo Boxes and spheres. they calculate the contact impulses, the friction forces, the full rigid body update, with inertia matrix, ect... the references are

Chris Hecker
Stephen Ehmann
Sigraff'97 course notes

Martin Baker

and
Rigid body simulation lectures




[edited by - oliii on April 1, 2004 3:27:07 AM]

Everything is better with Metal.

also, a very good read

impulse based dynamic simulation

Everything is better with Metal.

Thanks a lot! I''ll have to get reading... I checked out your 2d demo and was very impressed. A question though: It looks as if the circles in the demo are a construct of connected vertices - is it necessary to treat plain circles that way as it seems like it could be rather inefficient (as opposed to using one large particle)? Of course, using a system like that would allow you to create a polygon of any shape and size and have it bounce around the game world, right? Anyhow, thanks for all the help, I appreciate it. This might take me a while though .
it''s just the rendering, which is very low-tech. it''s a sphere (well, a solid circle) in reality. Polygons (at least convex polygons), would just be an extension of the box collision.

Everything is better with Metal.

This topic is closed to new replies.

Advertisement