drag and drop (RigidBody2D)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By prosta4ock
:warning: Old Version Published before Godot 3 was released.

Hi.
Tell me please how to make drag and drop physical objects (RigidBody2D)

I did, but I do not like the behavior of the body. I want to implement such a video.

:bust_in_silhouette: Reply From: Vincent Scalia

Under your if(Input.is_mouse_button_pressed()) try a line like this:

set_pos(Vector2(get_viewport().get_mouse_pos())

this will set the object to the vector current position of the mouse. Once you release the button, the object should continue it’s physics as normal.

I did, but I do not like the behavior of the body. I want to implement such a video.
https://youtu.be/QiLHc_zJNvA?t=2322

prosta4ock | 2016-06-06 18:35

:bust_in_silhouette: Reply From: prosta4ock

Maybe someone will need.
I decided to do it:

var r = Vector2(get_viewport().get_mouse_pos() - get_pos()) * speadDrag;
set_linear_velocity(r)

ooh. thats a good idea!

Vincent Scalia | 2016-06-06 20:26