reseting force problem

Official forum for the Chipmunk2D Physics Library.
Post Reply
abbasi
Posts: 9
Joined: Thu Apr 16, 2009 7:55 am
Contact:

reseting force problem

Post by abbasi »

hello i have made a vehicle using 2 wheels and a chassis. And i have some luggage on top of the vehicle. When the vehicle moves and the luggage falls then i need to reset the position of the vehicle and reset all forces and put the luggage on the top again.
I get the post step call back when the luggage hits the ground but when i do this to the vehicle

chassisBody->v = cpvzero;
chassisBody->f = cpvzero;
cpBodySetAngle(chassisBody, 0.0f);

it behaves very strangely.

The vehicle comes to rest alright but if its overturned then it behaviour is strange.

So what would be the best approach to bring the vehicle (connected bodies) to rest and put it at the right angle???

P S: i m using pivot and spring joints to connect the chassis with the wheels
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: reseting force problem

Post by slembcke »

Yeah, it will act weird if you suddenly move one, but not all of the bodies when they are jointed. In your case I think you will be fine if you just rotate the other body positions around the chassis. Something like this:

Code: Select all

// rotate other bodies around the chassis first
cpVect center = chassisBody->p;
cpVect rot = chassisBody->rot;
someBody->p = cpvadd(cpvunrotate(cpvsub(otherBody->p, center), rot), center);

// Then reset the chassis
chassisBody->v = cpvzero;
chassisBody->f = cpvzero;
cpBodySetAngle(chassisBody, 0.0f);
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
abbasi
Posts: 9
Joined: Thu Apr 16, 2009 7:55 am
Contact:

Re: reseting force problem

Post by abbasi »

yeah i think i get the reason why it is behaving like this. I used ure snippet like this

cpBodyResetForces(chassisBody);
cpBodyResetForces(frontWheelBody);
cpBodyResetForces(rearWheelBody);
cpBodyResetForces(carrierRightBarBody);
cpBodyResetForces(carrierLeftBarBody);

cpVect center = chassisBody->p;
cpVect rot = chassisBody->rot;
carrierRightBarBody->p = cpvadd(cpvunrotate(cpvsub(carrierRightBarBody->p, center), rot), center);
carrierLeftBarBody->p = cpvadd(cpvunrotate(cpvsub(carrierLeftBarBody->p, center), rot), center);
frontWheelBody->p = cpvadd(cpvunrotate(cpvsub(frontWheelBody->p, center), rot), center);
rearWheelBody->p = cpvadd(cpvunrotate(cpvsub(rearWheelBody->p, center), rot), center);



chassisBody->v = cpvzero;
chassisBody->f = cpvzero;
cpBodySetAngle(chassisBody, 0.0f);

But its still misbehaving :D. Any comments??
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: reseting force problem

Post by slembcke »

You'll have to be more specific than that. A picture is sort of helpful, but a video is worth 10,000 words.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
abbasi
Posts: 9
Joined: Thu Apr 16, 2009 7:55 am
Contact:

Re: reseting force problem

Post by abbasi »

ok i ve sent u the video link
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: reseting force problem

Post by slembcke »

What joints are you using, and how are you controlling the vehicle?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
abbasi
Posts: 9
Joined: Thu Apr 16, 2009 7:55 am
Contact:

Re: reseting force problem

Post by abbasi »

i m using groove and spring joint. To accelarate force is applied to the rear wheel. and same is the case for the braking.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: reseting force problem

Post by slembcke »

Maybe the rotation is actually backwards? I've been out for a wedding this week so I can't easily try it out. Try swapping cpvrotate() for cpvunrotate() maybe? Also try slowing the framerate after resetting it so you can see if things are lining up right.
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 10 guests