I'm messing with some Rigidbodies this week and trying to set an object position on x with the mouse and an offset where the click is done.
With the last KidsCanCode's video about Rigibodies, I understand that I should use
_integrate_forces(state) instead of
_physics_process but I still can't do what I want.
My problem is that the object follows the mouse click with the offset but it switch between positive and negative value (from the mouse I think) making my object glitching !
So here's my code to put on a Rigidbody2D:
var mouse = get_global_mouse_position()
var object_position = state.get_transform()
# GET VECTOR BETWEEN MOUSE AND OBJECT
var offset = object_position.origin - mouse
# ADD THE OFFSET
object_position.origin.x = (mouse.x - offset.x)