Page 1 of 1

moving a shape with mouse

Posted: Thu Mar 19, 2009 3:49 am
by nongio
hi all,
i'm searching the way to move a shape with mouse. I've seen that the default method to drag an object is to use a Joint between the target body linked to a shape and a body without a shape, then set the position of the second body.
I would know if it's possible to manage the object drag directly by the setting it's position.
I've tried to realize this on my own, but unfortunatly it goes right only for few seconds, then the shape doesn't collide with others. Why?

Re: moving a shape with mouse

Posted: Thu Mar 19, 2009 5:46 am
by ker
Setting the object's position directly is not very stable, because it will mess up the velocity calculations.

It not colliding anymore doesn't make any sense thou. I think it would be much easier to find your problem if you would post your source code here. Are you sure it won't start colliding again if you hold the object steady for a while?

Why don't you want to use the joint-method? There's even an easy to use cpMouse "object" somewhere in this forum.

Re: moving a shape with mouse

Posted: Thu Mar 19, 2009 6:02 am
by nongio
I don't want use the joint-metod because i don't want rotation during the drag. I want a simply translation

Re: moving a shape with mouse

Posted: Thu Mar 19, 2009 7:17 am
by slembcke
If you attach the joint to the center of gravity of the shape instead of at the point you clicked, you won't get any rotation.

Re: moving a shape with mouse

Posted: Thu Mar 26, 2009 1:14 am
by sksmith
Hi,


Rotation is impossible if you attach the joint to the center of any shape so choose the point where you click.