Collide Whilst Dragging An Object

Just wondering if it is possible to make a physical body collide with other bodies whilst it is being dragged?

The main body I am moving is “static” as are the other bodies [import]uid: 6981 topic_id: 4221 reply_id: 304221[/import]

bump [import]uid: 6981 topic_id: 4221 reply_id: 13128[/import]

does it need to be “static” in the first place?

try the platform collision demo. they collide with other objects during drag don’t they?

you could always have isSensor applied and then set repulsion forces on the objects colliding i guess [import]uid: 6645 topic_id: 4221 reply_id: 13141[/import]

Yup, has to be static or kinematic.

Its a spring that the user can move around on touch then a ball gets released and collides with the spring (the spring doesn’t move again unless touched/dragged, and is not affected by gravity). The problem is you can place the spring anywhere while dragging as collision detection seems to just stop whilst doing it.

In the dragging demo, some objects do collide whilst dragging yes, but take a look at the static objects, you can drag a static object straight though another in the demo.

Is this a bug or… [import]uid: 6981 topic_id: 4221 reply_id: 13142[/import]

I would be very careful about using static for bodies that can move, I think you will end up with unexpected results (like static objects being able to pass through each other). If you want a body that can move but is not subject to gravity then use kinematic.

You have been warned :wink:

[import]uid: 9371 topic_id: 4221 reply_id: 13170[/import]

Kinematic/Touch joint.

m [import]uid: 8271 topic_id: 4221 reply_id: 13172[/import]

Even using kinematic the problem still exists.

Check the dragme demo and you will see for yourself (the kinematic or static objects pass though each other but interact with the dynamic ones) [import]uid: 6981 topic_id: 4221 reply_id: 13182[/import]

What mechanism are you using to move the object? If you use the right body type and a touch joint you are, in effect, asking the object to go to the location you give it. If you are simply setting its x and y to a set value, you’re forcing it. The touch joint is part of the physics engine and so will respond better in conjunction with dragging objects against other objects. There are properties you can set to make it anything from extremely elastic to almost exactly under the touch point, but you will have to give up some limited flexibility. This, when you think about it roundly, is actually the intended result because if you want the object to be precisely placed then you don’t really want it in “the world” anyway.

Matt. [import]uid: 8271 topic_id: 4221 reply_id: 13187[/import]

Hey matt i think you are reading a little bit too deep into this simple problem. I emailed Carlos and he thinks it is a bug.

All i am trying to do is drag an object around the screen but without it “Going though” other objects.

I could fix this problem by disabling gravity and using all dynamic bodies, however this would create more work for me. I would have to either do it by changing all my static objects to dynamic objects (while dragging) to static on runtime (ie when the user is happy with the placement), then convert them back to dynamic if the user requires the positions changed… or just disabling gravity completely and using custom behaviours on my ball.

So in short, it’s making an incredibly simple thing into a complex mess.

[import]uid: 6981 topic_id: 4221 reply_id: 13423[/import]

Yeah, I tend to assume it’s not a bug.

Please post any success/response/fix won’t you?

M [import]uid: 8271 topic_id: 4221 reply_id: 13471[/import]

Try the demo and you will see it certainly must be a bug :wink:

I will definitely :slight_smile: [import]uid: 6981 topic_id: 4221 reply_id: 13578[/import]

The gameUI.lua library (see the MultiPuck project in the SDK) makes it easy to do this…it uses a temporary touch joint to make the object follow your finger/mouse.

There’s also a video about this:
http://blog.anscamobile.com/2010/11/tutorial-dragging-physics/

cheers,
Tim [import]uid: 8196 topic_id: 4221 reply_id: 13671[/import]

Ok so here is how i fixed it.

I set the gravity to 0,0 on the levels startup.
Then when the user clicks the go button i set the gravity to 0,9.8

When my ball isn’t active and my object is touched i set my object to “moveable”, and the gravity to 0,0 if it isn’t already, then when i release the drag i set it back to kinematic.

So more work but it works as intended now.

This was the only way I could achieve collision between static bodies without adverse side effects. If anyone wants more detail or maybe a demo I can provide it.

Cheers [import]uid: 6981 topic_id: 4221 reply_id: 13735[/import]