Objects bouncing off too hard

Official forum for the Chipmunk2D Physics Library.
Post Reply
igalic
Posts: 3
Joined: Mon Mar 30, 2009 5:41 pm
Contact:

Objects bouncing off too hard

Post by igalic »

Hi!

I'm pretty new to physics engines (this is the first one I've used), and I've run into some problems - hopefully people here have already encountered them and found some solutions :)

What I'm trying to do is have some objects on the screen, floating in liquid. To simulate the liquid, I've set the damping factor of the space. The objects (circles) interact well with each other, but I need to be able to pick one of them and drag it around the screen. That's when troubles start.
I've used the approach from cpMouse to drag the object around the screen, but I've had two problems. One was that it was easy to drag this object off the screen, but I've solved it by simply resetting the objects' position if they are out of bounds.

The other problem I have is that when you drag one object into the others they behave very strange - either they bounce off very very fast, or start spinning strangely. This especially happens if you put a few objects in a corner, and then try to "squeeze them out" with the object you're dragging. They seem to explode and start going off in all directions.
I assume it's expected behavior from the physics engine, but has any of you had such problems and what would be a good way to go about solving it? What exactly is causing this behavior?

Thanks,
Ivan
ker
Posts: 56
Joined: Tue Jul 15, 2008 4:13 am
Contact:

Re: Objects bouncing off too hard

Post by ker »

for the going off-screen part: do you have boundaries? if so, maybe your timestep is too large.

For the jiggery objects when pushed together, yea, that's pretty normal. Maybe playing around w/ iterations, timstepsize, elasticIterations and elasticity might improve the behavior a little.

You could modify cpMouse to use a slide joint instead of a pinjoint, this will lead to the object hanging below the mouse, but having a little more freedom of movement.
igalic
Posts: 3
Joined: Mon Mar 30, 2009 5:41 pm
Contact:

Re: Objects bouncing off too hard

Post by igalic »

ker wrote:for the going off-screen part: do you have boundaries? if so, maybe your timestep is too large.

For the jiggery objects when pushed together, yea, that's pretty normal. Maybe playing around w/ iterations, timstepsize, elasticIterations and elasticity might improve the behavior a little.

You could modify cpMouse to use a slide joint instead of a pinjoint, this will lead to the object hanging below the mouse, but having a little more freedom of movement.
Ah well, I can't get this to work the way I'd want it to, but I did manage to get some improvements. From the little I know about physics, I remembered that when two bodies collide, there was something about distributing the kinetic energy and also that the velocity after collision is inverse proportionate to the mass. So I did a little trick - all of the objects in my scene have a relatively high mass (100). When I grab an object, I set it's mass to a low value (0.1). Now, even if it moves very fast, it's kinetic energy is relatively low and when it hits other objects, they don't bounce off too fast because they are much heavier. Once I let go of the object, I reset its mass.
However, the problem now is that this dragged objects goes through other objects very easily :( I can't find a way to solve that - Chipmunk tries to move away other objects, but I obviously don't want them to move away too quickly. On the other hand, if they move too slow, my dragged object will overlap with them.

The real solution would be to somehow stop my object once it collides the other ones, preventing it from going into these other objects. But I don't know how to do that... I'm already updating Chipmunk at 1/180 s intervals...

Any ideas?

Thanks
Ivan
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Objects bouncing off too hard

Post by slembcke »

The problem is that the joint will try as hard as it needs to correct the position. This is bad because it tends to make anything stuck in the way of the clicked object (and the object itself even) freak out.

In the trunk code (http://code.google.com/p/chipmunk-physi ... e/checkout) I've implemented force limits on all joints so that you can set a maximum correction force. This mostly solves the problem, though still requires a lot of tweaking. The trunk code should be pretty stable as I use it for all of my own projects, but I haven't been keeping up on the documentation as much as I should.

I really should do a release sometime soon. If only it paid bills. :(
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
igalic
Posts: 3
Joined: Mon Mar 30, 2009 5:41 pm
Contact:

Re: Objects bouncing off too hard

Post by igalic »

Thanks for this!

I've downloaded the latest version from SVN and it works really great. Now there's no more strange behavior and it looks pretty natural. I think this property to joints was really needed...

Yeah, unfortunately sometimes doing the things we like doesn't pay...

Ivan
slembcke wrote:The problem is that the joint will try as hard as it needs to correct the position. This is bad because it tends to make anything stuck in the way of the clicked object (and the object itself even) freak out.

In the trunk code (http://code.google.com/p/chipmunk-physi ... e/checkout) I've implemented force limits on all joints so that you can set a maximum correction force. This mostly solves the problem, though still requires a lot of tweaking. The trunk code should be pretty stable as I use it for all of my own projects, but I haven't been keeping up on the documentation as much as I should.

I really should do a release sometime soon. If only it paid bills. :(
JC13
Posts: 6
Joined: Mon Jun 08, 2009 11:23 pm
Contact:

Re: Objects bouncing off too hard

Post by JC13 »

hey igalic,

did you have to make any modifcations to the cpMouse file to get it to work with the trunk version of the code on SVN? after updating, cpMouse doesn't seem to compile.

Thanks,
JC
Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests