Page 1 of 1

Restarting body/shape position

PostPosted: Wed Sep 24, 2008 7:49 am
by Patuti
Hello,

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.

Re: Restarting body/shape position

PostPosted: Wed Sep 24, 2008 5:16 pm
by ker
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

Re: Restarting body/shape position

PostPosted: Sat Sep 27, 2008 9:31 am
by Patuti
ker
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!