Page 1 of 2

How to move a non INFINITE MASS body?

Posted: Mon Feb 22, 2010 5:21 am
by zaldzbugz
Hi, do you have an idea how to move a body with a non-infinite mass. I tried moving some body but it only works with body of infinite masses.
I need your help.

Regards,
ZaldzBugz

Re: How to move a non INFINITE MASS body?

Posted: Mon Feb 22, 2010 7:48 pm
by Tam Toucan
Erm what exactly is the problem? The entire documentation and examples all deal with non-infinite masses. In fact I've never thought about trying to more something with infinite mass.

Re: How to move a non INFINITE MASS body?

Posted: Mon Feb 22, 2010 8:25 pm
by zaldzbugz
i wanted to try moving objects with non-Infinite masses using various animations or actions. Like MoveTo, MoveBy, JumpTo etc.

Re: How to move a non INFINITE MASS body?

Posted: Tue Feb 23, 2010 5:13 am
by Tam Toucan
Still not clear what you mean. Do you mean move as in directly change the position, not by applying forces? Or do you want to write a "jumpTo" function that works out the forces to apply to an object to make it jump to a given location?

Re: How to move a non INFINITE MASS body?

Posted: Tue Feb 23, 2010 8:09 am
by zaldzbugz
Yes, i want to use JumpTo to apply forces to an object to make it jumpto a given position. And this object has non-infinite mass.

Re: How to move a non INFINITE MASS body?

Posted: Tue Feb 23, 2010 2:25 pm
by Tam Toucan
Well there's not a nice easy general "do this" solution. For simple movement you could try cpBodySlew. JumpTo is harder. Normally you would have a fixed jump, not a "jump from here to there" (where the 'there' can be anywhere relative to 'here'). Do you really need that? Can you not have a few fixed jumps? i.e. you have different impulses that "throw" the object in desired arcs.

Couple of ideas. Hopefully someone who's tried this will have some better help
1) Look at this thread. Think of the jump as trying to fire a ball from the current point to the desired point.

2) Somehow calculate a curve from the 'here' to 'there' and use cpBodySlew to move towards a set of points along it's path.i.e. pick (say) 5 points on the curve and move towards the first, once near move towards the next etc. I suspect it would be very hard to stop jerky/angular movement

3) It might be possible to use constraints. Look at how the grab with mouse code works (I'm sure the demos have some, also there is this. Now imagine setting the point you want to jumpTo as the mouse position. The object will be pulled towards it (in a straight line). Now by adjusting the velocity you should be able to get a curve.

Re: How to move a non INFINITE MASS body?

Posted: Fri Feb 26, 2010 4:07 am
by zaldzbugz
great Tam..thanks

Re: How to move a non INFINITE MASS body?

Posted: Mon Mar 08, 2010 9:39 pm
by zaldzbugz
Hi again. i have an INFINITE mass object that is added to a layer in which this layer is moving. is there a way that this INFINITE mass object will also move relative the layer where it was added? I tried but the only one that is moving is the shape->data on an object as sprite and not including the body.

Re: How to move a non INFINITE MASS body?

Posted: Mon Mar 08, 2010 11:36 pm
by Tam Toucan
Sorry you'll have to rephrase that. Layers don't move. Layers in Chipmunk are the term used for the cpBody.layers member which defines which other layers the shape will collide with See the wiki here.

Re: How to move a non INFINITE MASS body?

Posted: Mon Mar 08, 2010 11:42 pm
by mobilebros
It sounds like he means layer in the Cocos2d sense.... why don't you just match up your chipmunk coordinates with the layers coordinates... in other words make your chipmunk coordinates be relative to your layer's anchor/position, then it won't matter if your layer is moving or not as its all relative.