Force value issue

Official forum for the Chipmunk2D Physics Library.
User avatar
CocoaGeek
Posts: 18
Joined: Thu Aug 27, 2009 10:32 am
Contact:

Force value issue

Post by CocoaGeek »

Hello,

I'm running into a bit of a weird issue tonight. I'm trying to lift a body from a surface (static body) by applying a force to it.

Since I'm using real-world value (and SI units), I'm expecting the value for the force (in Newton) to need to be greater than Mass * Gravity in order to cancel the action of gravity and lift the body. However, what I'm seeing is that I need to multiply the force by 4, for it to have the expected effect.

The same issue manifest it-self if I set the body high above the surface. The body will only stay stationary if the lift force is multiplied by 4.

Any idea of what could be wrong? I'm probably doing something stupid, but I can't seems to see what exactly could cause this ... :oops:

Thanks in advance.
User avatar
CocoaGeek
Posts: 18
Joined: Thu Aug 27, 2009 10:32 am
Contact:

Re: Force value issue

Post by CocoaGeek »

Hmmm ... Anyone else using real world values?
mobilebros
Posts: 90
Joined: Tue Aug 04, 2009 9:53 am
Contact:

Re: Force value issue

Post by mobilebros »

I have not had this issue, I'm almost positive that to cancel gravity I've just done an equal and opposing force of gravity *mass..... could it have something to with where you applied the force on the body, I've always done it on the center of gravity.... or perhaps your calculated moment is wrong.... I'm just stabbing in the dark i'm in no way positive if that would even affect anything having to do with this issue.
User avatar
CocoaGeek
Posts: 18
Joined: Thu Aug 27, 2009 10:32 am
Contact:

Re: Force value issue

Post by CocoaGeek »

Thanks for the reply :) I have tried to apply the force directly on the center of gravity (it was applied with a Y offset) and also changed the inertia value of the one of the disc of the same weight, but no change whatsoever :cry:

Could it be that I have expressed the gravity incorrectly? I specified it in m/s (e.g (0.0f,-9.8f) )
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Force value issue

Post by slembcke »

I forgot my Macbook's power supply at the place we do contracting at so I can't really try anything out right now, but it should work just fine...

The integration just calculates the acceleration like so:

Code: Select all

cpvadd(gravity, cpvmult(body->f, body->m_inv)
So if g=-f/m, then f = -g*m. Not exactly sure why that wouldn't be working.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
CocoaGeek
Posts: 18
Joined: Thu Aug 27, 2009 10:32 am
Contact:

Re: Force value issue

Post by CocoaGeek »

Thanks Scott, I can wait a few days until you get your power supply back ;-)
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Force value issue

Post by slembcke »

The following works for me:

Code: Select all

	ballBody->f = cpvmult(space->gravity, -ballBody->m);
Are you sure you aren't changing the gravity or mass after setting the force?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
CocoaGeek
Posts: 18
Joined: Thu Aug 27, 2009 10:32 am
Contact:

Re: Force value issue

Post by CocoaGeek »

Yeah ... The only think I do, and don't think it's an issue, is to reset all the forces applied to all bodies after each time step. Could that be the issue? :oops:
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Force value issue

Post by slembcke »

No, that should be fine.

You should check some of the values in cpBodyUpdateVelocity() in the debugger. The following should evaluate to zero unless something is very wrong:
cpvadd(gravity, cpvmult(body->f, body->m_inv)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
CocoaGeek
Posts: 18
Joined: Thu Aug 27, 2009 10:32 am
Contact:

Re: Force value issue

Post by CocoaGeek »

Will do, thanks for the suggestion(s).
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests