Reduce Velocity

Official forum for the Chipmunk2D Physics Library.
Post Reply
between 3 and 20
Posts: 5
Joined: Thu Feb 13, 2014 5:33 am
Contact:

Reduce Velocity

Post by between 3 and 20 »

Hello

I have a non gravity environment. Bodies need to move to a specific coordinate and there they should stop slowly or interpolate a bit around the point. I need to use applyforce because pivot needs to much performance. How to achieve this? I dont want to use resetForces. I think I need something like a brake.

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

Re: Reduce Velocity

Post by slembcke »

Well, the general way to do that is to say that you want the object to move some fraction of the way to the target position within the next frame, say half way there. Then you figure out what velocity the object would need to be moving at in order to move to that position and what force you would need to accelerate to that velocity.

By adjusting the fraction, maximum allowed velocity and maximum force, you can get a pretty good behavior. This is quite close to what Chipmunk's joints are doing, but those are applied in a much more expensive way since they need to be solved as hard constraints.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
between 3 and 20
Posts: 5
Joined: Thu Feb 13, 2014 5:33 am
Contact:

Re: Reduce Velocity

Post by between 3 and 20 »

How do I add maxforce and maxvelocity with applyForce?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Reduce Velocity

Post by slembcke »

Well, you don't. You have to calculate it all yourself. You apply a max velocity by not accelerating the body when it's already going fast enough, and max force by not setting the force value to a large value.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
between 3 and 20
Posts: 5
Joined: Thu Feb 13, 2014 5:33 am
Contact:

Re: Reduce Velocity

Post by between 3 and 20 »

Thanks. Do you mean by fraction, friction?

Is this also happening when the body doesnt touch any other object or floor? As its top down zero gravity.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Reduce Velocity

Post by slembcke »

Sorry, left this tab open on my iPad for like a week. :-\

I meant fraction, like a percentage.
between 3 and 20 wrote:Is this also happening when the body doesnt touch any other object or floor? As its top down zero gravity
Not sure I understand the question. This is how you would implement that.
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: Bing [Bot] and 31 guests