Draggable and Physics Automatisms don't work together

In my little project I have two sprites. One is stable (o) and second one (dot) is forced to move toward first. Beside Physics I’ve added Draggable Automatism to second one (dot) but it don’t work. I can’t move this object using mouse (Physics is still working fine). Is it possible to use both automatisms for one sprite?

You’re absolutely right… draggable and physics automatism don’t work together, at least not at the same time.

You can’t drag an object in one direction while the physics automatism is “dragging” that object towards the gravity specifications you set for it. It’s like two forces pulling an object in two different directions, and the physics automatism will always win.

You can set the two automatism to the same object and make it work BUT there can be only one of them active at the same time:

  • Set the two automatism to the object
  • At the scene start, deactivate the draggable automatism
  • If the mouse button is pressed over the object (add a “trigger once” condition here, to perform the following actions just one time while the button is pressed):
    [list][*]Deactivate the physics automatism
  • Activate the draggable automatism
    ]If the mouse button is NOT pressed over the object (add a “trigger once” condition here, to perform the following actions just one time while the button is NOT pressed):
  • Activate the physics automatism
  • Deactivate the draggable automatism

That should allow you to “lift” an object with the cursor and see it fall when you release it.

It works, thanks again!

[edit] One more thing. Can I disable automatism for clicked instance only? I’ve disabled it for object, and when I click over one instance physics is disabled for all instances.

Hm, Could you please show us your events? I thing there’s something wrong with them as it should work only for clicked instance.

Here you are

Add to this event “Mouse is over object dot”. That should solve the issue.

Like this? Still the same problem.

Hm… I don’t know then. Let’s wait for Lizard-13 or Victor, maybe they’ll know.

I’m testing it now, with the same events and everything works fine (native and HTML5), only the physics of the clicked instance is deactivated… :confused:

Please check the file, let me know if it works (or not) :slight_smile: :
DeactivatePhysics.zip (6.54 KB)

Maybe problem is somewhere else. Check out this short movie. It seems like position of instance is somehow remembered when I drag it off. Look at the pile of squares. They don’t collapse until I release dragged instance. That’s why I thought that physics is disabled for every instance.
Should it work that way?


I’m sorry, I forgot to reply your message :blush:

:exclamation: This could be a lot of “useless theory”, really I don’t know how it works :stuck_out_tongue:
It could happen because when you deactivate the Physics automatism, you are “pausing” its physical body, I think. Surely there are two objects, the GD sprite and a “virtual entity” (virtual entities inside virtual objects, yeah), virtual because you don’t see it. This virtual physical body is the Box2D body, it follows the laws of physics inside the Box2D world representation… while the automatism is active, and the Sprite object get info from it to move around.
When you deactivate the physics automatism, the body is “removed” from the Box2D world, and the sprite doesn’t copy the info related to position, rotation, etc. so you can move it around, for example dragging it.
Finally, when you activate the automatism again, the physic body is added to the world again, but in the same position it has when you deactivated it. That would explains why, after stop dragging the object, it returns to the old position. Of course it appears over other physics objects, and a push-out force is applied :slight_smile:

Try to set the object position = mouse position, after activating the automatism again, I can’t test it now, but maybe changing an object position with the physics automatism active, change the physic body position too :confused:

When dragging turn off the automation
when not dragging turn on the automation