I've programmed a 2D physic engine in my PPL program with gravity, velocity, elasticity, friction and such. I only have a problem with ball type objects. Once they touch an object while going down and that the speed is very low, they get stock. The problem is that a ball might get stock on top of another ball. I would like to simulate rolling. Does anybody have a clue how it works? What if the object the ball is on is at an angle, how will the ball know to roll in the right direction?
If you mean the objects come to a halt but gravity is not enough to keep the objects moving against friction. What you have is like two interlocked gear wheels. So gravity does not need to overcome friction as touching surfaces do not unlock in the direction gravity occurs. Just calculate a small period of time with the resoulution of gravity at a tangent to the contact, resulting in the free object spinning (You've seen cogs opposite directions). They may build up enough to break touching gravity and leave the touching system.
Unless you mean something else.

Jinks: I think he means two balls on top of each other. In the current PPL sprite demos, there's one that has a bunch of bouncing balls. Since the physics aren't quite up yet, right now they can get stuck on top of each other, instead of rolling off of each other like they would in real life.
To do that, I'd imagine that you'd look at the angle to determine where it's sitting on - if it's going to roll left, it'll be sitting at angles 270-359, annd to roll right, you'd look for an angle 0-90. Afterwards, there would be some trig involved in order to figure out how fast it should accelerate, though I'd imagine you could cheat and just use a normal acceleration around the circle.
If you want to solve this properly, you need to build a matrix with all your constraints and solve it. This is far from trivial, and probably not doable on PPC.
I say: just fake it. If the horizontal position of the ball on top is above, roll to the left, else to the right. I guess this is what Sponge was saying.
Ok, I thought about it for a while and came up with this:
If ball cannot move down anymore and collide, check if collide when moving to the left, if not, move, then it will fall a bit more. If collide then try moving to the right, if not collide, move right, it will fall etc... I will try moving in the direction based on the center of the colliding object first. If the ball is more on the left, i will try to move left first...
What do you guys think?
Ok, I thought about it for a while and came up with this:
If ball cannot move down anymore and collide, check if collide when moving to the left, if not, move, then it will fall a bit more. If collide then try moving to the right, if not collide, move right, it will fall etc... I will try moving in the direction based on the center of the colliding object first. If the ball is more on the left, i will try to move left first...
What do you guys think?
It might be a good idea to randomly choose which side to check first. In some games if a player knows that the physics engine is always going to "roll left" its unrealistic and open to being exploited.
Crayfish
Hey good idea. I didn't think of that.
Thanks a million!
Makes sense, but if there's no overlapping values, how will that help? That's the only situation when randomizing it would be beneficial.