Elastic joint(?)

Official forum for the Chipmunk2D Physics Library.
Post Reply
Lobster
Posts: 4
Joined: Tue Oct 20, 2009 11:01 am
Contact:

Elastic joint(?)

Post by Lobster »

Hi.

Trying to make elastic drag effect like on the video:
http://dl.getdropbox.com/u/989832/elastic-video.mov

Tried to use joints (one of the body has infinite mass), but ball just moved to the target without any elastic effect.

How this effect could be implemented?

Thank you!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Elastic joint(?)

Post by slembcke »

Looks like they simply damp the velocity of the white ball and apply a spring force towards the control point.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Lobster
Posts: 4
Joined: Tue Oct 20, 2009 11:01 am
Contact:

Re: Elastic joint(?)

Post by Lobster »

Should I connect the controlling ball with moving ball using a joint?

Seems the force applied to the moving ball depends not on the controlling ball's velocity but on their distance.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Elastic joint(?)

Post by slembcke »

No joints. Just damp the velocity (v = v*0.99 or somesuch) and apply a force based on how far the ball was from the control point (f = (point - ball_center)*some_number)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Lobster
Posts: 4
Joined: Tue Oct 20, 2009 11:01 am
Contact:

Re: Elastic joint(?)

Post by Lobster »

Thank you for the answer.

But the applied force will infinitely move the ball without spring effect? Maybe an impulse should be applied? Or every time ball flies over the control point we should apply a force with negative direction to the current force with damping coefficient?

One more question: after applying an impulse body never stops like there's no friction (body is in the air, without gravity). How to simulate air friction?
Also body never stops after applying an impulse while it's on the ground (but body and ground have non-zero friction coefficients). Body is a circle.
Even if I add surface_v to the ground my body is just rotating at the same position, it does not move.

Thanks!
Lobster
Posts: 4
Joined: Tue Oct 20, 2009 11:01 am
Contact:

Re: Elastic joint(?)

Post by Lobster »

Thanks again, I got the desired spring effect =)

That is done on every tick:

Code: Select all

ballBody->v = cpvmult(ballBody->v, .93);
distDiff = cpvsub(mBallBody->p, ballBody->p);
forceApplied = cpvmult(distDiff, 800.);
cpBodyResetForces(ballBody);
cpBodyApplyForce(ballBody, forceApplied, cpvzero);
Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests