How to stop movement of physics object with touch?

I have a game level with some static objects on screen. I also have an object with a physics body (dynamic) which can be moved around by screen touch. When the object collides with another physics static object the physics body stops on the other object and can not “break” through the outside of the other object. But when I move my finger exact over the static objects mid the dynamic object “jumps” to the center of the static object.

How can I prevent the object from doing this? It should not be “enter” the other object.

Thx for your help!

Don’t update the x,y directly.  Use a touch joint to move the dynamic block.

I show how to do this as part of an old sampler I did for the Corona Geek show:

http://github.com/roaminggamer/CoronaGeek/tree/master/Hangouts/Sampler

Direct link: http://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/Sampler/sampler.zip

See this code:

http://github.com/roaminggamer/CoronaGeek/blob/master/Hangouts/Sampler/sampler/examples/pulley_joint/helpers.lua

As the roaminggamer said,

that’s the way to go.

If you only want to use the collision detection (no physics involved) and for that sake als bodys are sensors, the approach of moving the body directly is fine in most cases.

Thank you for this detailed help!

I set it up and I can move the object now but how can I use a touch joint to be still have some kind of “snapping” to the object? I mean before I had the possibility to move the object “against” a wall object and when I moved my finger through the wall the object was stopped on one side of the wall until my finger went out of the wall on the other side and the object “snapped” to the other side of the wall.

With the touch joint this now is not working anymore because the object always stays on one side of the wall (and sliding there depending on my finger screen position)

Do some extra calculations to determine when your finger is far enough right or left of the ‘wall’, then force translate the drag-object by setting its <x,y> position manually.

Thx for the tip. I do this now and it normally would work BUT I still have a problem: The object I want to use is also a physics object and it has an active collision which prevents a manual movement because of active number crunching.

I tried to make the body inactive to move it, but this also isn’t working.

How can I move a physics object manually during a collision?

UPDATE:

I now use a timer with a 50ms delay before setting the physics objects body to inactive, then move it to it’s new position and activate the body again.

This is working now BUT: is this the best way to do this… it seems a little bit like “hack” here and I want to make sure my game is stable.

If you want to modify ANY physics system attributes (i.e. modify or create bodies) during a collision, you MUST use the ‘deferred execution’ hack you’re using. 

The reason for this is that the Box 2D code needs all physics bodies essentially locked while it processes them and collision detections and responses are part of the ‘processing’.

Note: A single millisecond is all you need for the timer delay.  That is enough delay to tell Corona: “Do this work in the next frame”.

Thank you for the details! This really helps a lot!

Don’t update the x,y directly.  Use a touch joint to move the dynamic block.

I show how to do this as part of an old sampler I did for the Corona Geek show:

http://github.com/roaminggamer/CoronaGeek/tree/master/Hangouts/Sampler

Direct link: http://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/Sampler/sampler.zip

See this code:

http://github.com/roaminggamer/CoronaGeek/blob/master/Hangouts/Sampler/sampler/examples/pulley_joint/helpers.lua

As the roaminggamer said,

that’s the way to go.

If you only want to use the collision detection (no physics involved) and for that sake als bodys are sensors, the approach of moving the body directly is fine in most cases.

Thank you for this detailed help!

I set it up and I can move the object now but how can I use a touch joint to be still have some kind of “snapping” to the object? I mean before I had the possibility to move the object “against” a wall object and when I moved my finger through the wall the object was stopped on one side of the wall until my finger went out of the wall on the other side and the object “snapped” to the other side of the wall.

With the touch joint this now is not working anymore because the object always stays on one side of the wall (and sliding there depending on my finger screen position)

Do some extra calculations to determine when your finger is far enough right or left of the ‘wall’, then force translate the drag-object by setting its <x,y> position manually.

Thx for the tip. I do this now and it normally would work BUT I still have a problem: The object I want to use is also a physics object and it has an active collision which prevents a manual movement because of active number crunching.

I tried to make the body inactive to move it, but this also isn’t working.

How can I move a physics object manually during a collision?

UPDATE:

I now use a timer with a 50ms delay before setting the physics objects body to inactive, then move it to it’s new position and activate the body again.

This is working now BUT: is this the best way to do this… it seems a little bit like “hack” here and I want to make sure my game is stable.

If you want to modify ANY physics system attributes (i.e. modify or create bodies) during a collision, you MUST use the ‘deferred execution’ hack you’re using. 

The reason for this is that the Box 2D code needs all physics bodies essentially locked while it processes them and collision detections and responses are part of the ‘processing’.

Note: A single millisecond is all you need for the timer delay.  That is enough delay to tell Corona: “Do this work in the next frame”.

Thank you for the details! This really helps a lot!