Restarting body/shape position

Official forum for the Chipmunk2D Physics Library.

Restarting body/shape position

Postby Patuti » Wed Sep 24, 2008 7:49 am


I've got the following situation...

A ball that is kicking around in a room, when it's Y component reaches a certain value it should have its own position restarted at a fixed X, Y so it can free fall and start kicking around all over again.

I've already tried the following approaches:

    Freeing the body and the shape and initializing it again as in first time.
    Manually setting the body's position to the initial X, Y and setting cpvzero to velocity.

In the first try what I got is almost what I want, the ball restarts at the position required, but to me it seems that the ball's velocity is kept, because you can clearly see that the velocity the ball had before the restart seems to be the same that it starts (instead of starting with velocity = cpvzero), even if I manually set the body's velocity to cpvzero.

In the second try, that I believe that is the worst option, the shape loses itself, I can't keep track of the position, it's as if I removed the body from the space, because the position is not updated anymore.

I'm still a beginner with Chipmunk, so there's a great chance that I'm trying bad approaches to this problem. So any suggestion would be great

Please, any help is appreciated.
Posts: 2
Joined: Mon Sep 22, 2008 12:04 pm

Re: Restarting body/shape position

Postby ker » Wed Sep 24, 2008 5:16 pm

just to make sure I'm not lying i just tried your second way (which is the obvious and right one, the first one uses too much cpu time)

I set the position to my x,y I want
then I set the velocity to cpvzero
also I resetForces every frame, therefore I don't have to do that there, try, that, too

I'm using my own c++ wrapper, so I can't post any code that'll help you, but if you post yours for the 2nd version, maybe someone sees your mistake
Posts: 56
Joined: Tue Jul 15, 2008 4:13 am

Re: Restarting body/shape position

Postby Patuti » Sat Sep 27, 2008 9:31 am

Actually, you've just said what I've forgotten when I posted the issue here...

I was setting body's position, velocity to the default position but forgot about the cpBodyResetForces... in the same day I posted the issue here I tried that out and it worked, but I've been really busy since then so I forgot to post the solution here!

But here it its, there was only a lacking cpBodyResetForces, that's all I needed, I hope it helps someone with the same problem...

Thanks for your help!
Posts: 2
Joined: Mon Sep 22, 2008 12:04 pm

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest