How to move an object with mouse without draggable behavior?

i managed to get a round object to roll and be as realistic as possible but another problem comes up which is i need to be able to throw the object i’m dragging . how can i do that ?

what i did was :-
1- LMB is down on object “round object” : deactivate physics
the mouse is over the object

2- LMB is “not” down on object “round object” : activate physics

Draggable behavior is always active …

I’m pretty sure that the problem is in draggable behavior >> when i hold the object the physics are just gone >> so when i just leave the object in the air it will just fall straight down because now physics is activated . but i can’t throw it left or right in the air .

My question here would be … how can i throw an object to the left or right with mouse? >> or how can i just move an object with mouse without the draggable behavior because it absolutely destroy what physics do if the object is being thrown "or in air"left or right ?
hope someone understands what i mean by all of this … sorry it’s my first time dealing with physics in gdevelop.

Hope someone helps .

Can anyone help please ? i’m very lost at this one . How to throw an object left or right when dragging in air ?

You could create variables for the object position:
x_old, x_current
y_old, y_current
The “_old” variables hold the position value from the last frame (iteration of the event sheet)
When the mouse button is released you could calculate the direction between the last point and the current one. For the speed you can calculate how far away from each other the two points lie. Then apply the values as movement to the object when the drag is over.
But this includes math which I’m pretty bad at, sorry. :blush:

It’s an old example, physics behavior only (draggable behavior can’t be mixed with physics). As you can see it’s as easy as mark the clicked object as being dragged or not, and while dragging it set the linear velocity in function of the cursor distance, the effect is almost as good as any physics mouse joint (it just doesn’t take into account the drag click point, always from center):
MouseJoint.zip (8.74 KB)
@ddabrahim Maybe you want to check this one :slight_smile:

Lizard-13 you just saved me . i just have one problem … how can i apply this to a second duplicate of the same object ?
i tried for each object condition but didn’t work …
thank you so much … this looks very complicated but still you are really a genius .

Looks great thanks for sharing :slight_smile:

However I’m no longer plan to share examples made by 3rd party on my itch.io only ones I make. I helped 4ian to bring some old GD4 examples to GD5 that was not available in JSON but that’s all.

I believe there is an examples room (or however it called) at Discord, you can link this topic there then 4ian may going to add it to GD or submit on GitHub :slight_smile:

Ok, I’ve forgotten the new-examples channel :stuck_out_tongue:

Instead use a scene variable select one of the objects under the cursor and use an object variable:

Conditions: Mouse button pressed Trigger once Actions: No actions // Sub-event Conditions: Cursor is over Player Actions: Pick a random Player Do = 1 to variable dragged of Player
Replace other conditions/actions using the scene variable by the object variable.

Awesome working great … thanks a lot for the great help