0 votes

I've coded a kinematic body 2D to be able to be picked up and dragged around with this code (ignore the grabbed = grabbable.GRAB)

func _process(delta):
if grabbed == grabbable.NO_GRAB:
if (mouse_in && Input.is_action_pressed("left_click")):
 dragging = true
if (dragging && Input.is_action_pressed("left_click")):
    var position = get_viewport().get_mouse_position()
     dragging = false

which works perfectly fine for the dragging system i wanted, except for 3 things, one of which i sort of know how to remedy.
The first issue is that wherever i click on the screen, the body teleports to the mouse position, as opposed to only being picked up when the mouse is over the body.

The second issue is that the body does not travel with the mouse, but rather quite a bit to the side of the mouse position, with the velocity of the body being proportional to its distance from the cursor when being dragged. I initially thought this was an issue with me having the sprite and collision shape not properly lined up with the actual body, but that isnt the case as they are lined up.

The third thing is that i can currently drag the body through walls, and if released when inside a wall it just pops out. is there a way i can prevent the body from ever being allowed through walls, while still having it follow the mouse?

in Engine by (17 points)

right ive solved the teleporting thing but still have the positioning issues

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.