Curved Ramp?

Post Reply
BigZaphod
Posts: 7
Joined: Wed Mar 25, 2009 5:31 pm

Curved Ramp?

Post by BigZaphod »

(insert physics newbie disclaimer)

I'm trying to build a shape like a skeeball lane with a ramp at the end: http://farm1.static.flickr.com/5/4649778_35c91e1a3c.jpg

When I roll a ball down this ramp with enough speed to launch it off the ramp, it can sometimes glitch (depending on how much initial force I give the ball) in such a way that when it hits the ramp it'll either slow way down, veer off in some weird/unnatural angle, or bounce straight back as if it hit a wall.

I built the lane out of several convex hulls. The main length of the lane is a single hull, but the ramp itself is made up of 8 other hulls sliced vertically (so it's 8 progressively taller boxes setting right next to each other with slanting tops so it gives the ramp it's curved shape).

My guess is that when the ball is moving fast enough, it penetrates one or two of the ramp's hulls in a weird way and then hits one farther in causing weird reactions. So to combat this, I tried to turn on the Ccd for the ball using this:

Code: Select all

rigidBody->setCcdMotionThreshold(kGeometryBallRadius);   // ball radius is 3.5 units
rigidBody->setCcdSweptSphereRadius(0.2*kGeometryBallRadius);
It appeared to help, but it didn't stop the problem. My understanding was that it'd do continuous collision if the ball moved > 3.5 units in a time step. Shouldn't that prevent this from ever happening?

This is probably not the best way to model this shape. I thought about using a height map instead, but it's not clear to me if that would really help the situation with a fast moving ball or not. Suggestions?
Last edited by BigZaphod on Fri Apr 17, 2009 8:14 pm, edited 1 time in total.
BigZaphod
Posts: 7
Joined: Wed Mar 25, 2009 5:31 pm

Re: Ramp?

Post by BigZaphod »

Can anyone help with this?

I've changed my code so that it builds the ramp from a bezier curve. That made it easy to adjust the number of slices the ramp is made up of to see if there's any change in the behavior. Sadly simply having more slices doesn't seem to matter much.

My new theory is that it has something to do with the fact that the ramp is actually made up of many box-like shapes with flat (but sloped) edges. When the ball hits one of those, I would assume Bullet needs to get the normal of the surface and then re-apply the forces according to that angle. If it hits a block who's slant is, say, near 45deg, then the ball shoots straight up as if all forward energy was transfered into upward energy. Which makes sense, but a real ramp with this sort of shape doesn't seem to behave that way.

I'm trying to figure out if it's actually the shape of my ramp that's wrong, or if it's something to do with how the collisions take place. I assume that if it is the latter, I could, in theory, build a custom collision shape based on my bezier curve so that the exact normal could be computed at the exact point of impact of the sphere - and that might make it act more correct. Although if what I'm doing should work, then perhaps my curve is simply not quite right.

Here's the simple rendered side view of my ramp shape as it is now: Image
BigZaphod
Posts: 7
Joined: Wed Mar 25, 2009 5:31 pm

Re: Curved Ramp?

Post by BigZaphod »

Ok, I think I know what's wrong. It's probably documented someplace obscure.. :)

I'm pretty sure the issue is when the ball makes contact with two parts of the ramp at the same moment. When this happens, it appears to be solving the situation by applying corrective forces for each collision point and then adding them together or something like that to come up with the final force vector that is applied to the ball.

The issue is that if the front of the ball is deep inside a part of the ramp, the engine sees that as a correction in need of a large counter force. While the bottom of the ball may be penetrated into a ramp only a small amount, so it gets a relatively small correction. When the forces are added together, the big forward penetration's correction force "wins" so to speak, and so makes up the majority of the vector of the ball afterward. This translates to the rather unnatural case of the ball seemingly hitting a wall or flying more vertically than it seems like it should (sometimes going back the way it came, adding a weird spin, whatever).

Nature tries to minimize energy usage, and a change in vector requires using some energy. What should really happen in reality is more along the lines of: when the collision of two points occurs, the collision which takes the least amount of energy is rectified first. In this case the ball's bottom collision point would be resolved and thus the ball is pushed up slightly. This changes the collision at the front of the ball which would need to be recalculated before any corrective forces are applied (if the collision even happens at all after the adjustment). My guess (without understanding much of any of the bullet internals) is that it doesn't work this way in the engine. Therefore multi-point contacts are, essentially, undefined and results in unrealistic behavior.

Is that even close to right? Not being very good at this kind of low level stuff (and having more of an intuitive sense of physics than an actual scientific one), I could be laughably wrong.

Assuming any of this is true, is there a real fix for this? I got slightly better results trying to replace my ramp with a btCylinderShapeX after I decided it might be a multi-contact issue. It kind of works, but of course it doesn't match the real shape or behavior of the ramp that was intended so it doesn't feel entirely right. But it's closer and at least seems to have less problems with the ball acting strange at varying speeds. (Although for some reason it seems like my ball has a huge spin or something sometimes because it'll hit the cylinder and then kind of shoot off to the left or right - but not all the time, just at certain speeds. Very weird.)

</ramble>
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Curved Ramp?

Post by Erwin Coumans »

The contacts might be generated ahead of time, which could make collisions against 'internal edges' worse.

Can you try to set the contact processing threshold to zero, and see if that improves things?

Code: Select all

collisionObject->setContactProcessingThreshold(0.f);
Hope this helps,
Erwin
BigZaphod
Posts: 7
Joined: Wed Mar 25, 2009 5:31 pm

Re: Curved Ramp?

Post by BigZaphod »

Thanks Erwin - unfortunately I don't see any difference. I put my ramp slices back in and removed the cylinder hack and setContactProcessingThreshold(0.f) on each ramp slice and didn't see any difference. I then set it on the ball as well, but there wasn't any difference with that, either. As far as I can tell, it didn't change anything. :/

The ball moves toward the ramp, hits it, and then depending on the speed of the ball it'll shoot up in a normal arc, shoot almost straight up, or it'll go over the ramp but seemingly lose a lot of momentum in the process. Is there anything else I should check or is this just not likely to work this way?
Post Reply