Keeping a body (balloon) upright by correcting its angle?

Official forum for the Chipmunk2D Physics Library.
Post Reply
fluxtah
Posts: 2
Joined: Fri Dec 03, 2010 4:56 am
Contact:

Keeping a body (balloon) upright by correcting its angle?

Post by fluxtah »

Hi,

I am trying to make a body correct its angle, because I want to give the effect of it keeping itself upright, the body is presented as a helium balloon that can bounce off walls.

I apply an upward impulse to the balloon to give the effect of being lighter than air. I have tried keeping it upright by damping the angle as follows:

float angle = body.getAngle();
angle *= 0.75f;
body.setAngle(angle);

It works ok but not fantastically.

Excuse the Java, I have made some Java bindings for chipmunk but you get the idea.

I also tried adding a PinJoint constraint and attaching a body with more mass to the bottom of the balloon but the effect was undesirable since it would bounce and loop around as if it was anchored, as one would expect.

Can someone with more experience advise me of a better way.?

Thanks in advance and thanks for such an awesome physics engine!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Keeping a body (balloon) upright by correcting its angle?

Post by slembcke »

Using a damped rotary spring might get the effect you want. The damping would make it look balloon-like, though the default spring force might not work so well. You can override the spring force by implementing a callback to calculate the force based on the angle of rotation of the ballon.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
fluxtah
Posts: 2
Joined: Fri Dec 03, 2010 4:56 am
Contact:

Re: Keeping a body (balloon) upright by correcting its angle?

Post by fluxtah »

Thanks it worked perfectly!
omnius
Posts: 16
Joined: Sat Nov 26, 2011 1:09 pm
Contact:

Re: Keeping a body (balloon) upright by correcting its angle

Post by omnius »

What should the second body be in such a constraint?

Presumably, it would be a body directly above the body you're trying to keep upright, but that seems to create additional overhead as now I have to force one body to always be in sync with the other - the same amount of work as just keeping the first body upright manually in the first place! For example, if both bodies are affected by physics, what's to keep the second body from actually making the angle of the first *worse* (not upright) because it's moved off to the side or under it?

I am just not visualizing this solution clearly enough, could you provide some more tips? Thank you.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Keeping a body (balloon) upright by correcting its angle

Post by slembcke »

The second body would be a static body. Either the static body for the space or a new one. Whatever is more convenient. The roary spring only affects the rotation so the position doesn't matter.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest