The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes


I'm in a bit of a predicament. I'm trying to create a map puzzle so basically moving the states to their correct location. Unfortunately I can't even click on the state never mind moving it. I know there is some similar questions out there but none of them have worked.

I've tried the sprite as an a child and the parent of an area2d with a collisionShape2d. didn't work. I tried connecting an input to the area2d and collisionShape but I got a target error so I added a a script to the collision still didn't work. The only thing that seemed to have any kind of effect was adding the sprite to a control and using an input which automatically coded it for me. But it seemed I couldn't even click on it and I couldn't even replicate the results. Sometimes it would completely crash the preview.

I don't if this has any effect or if it's helpful but I'm using 2.1.4 and a Mac.

Is there something I'm missing? what would be the right way going about this?

in Engine by (12 points)

Would you mind providing a minimal sample project including the code you have already written?

The code I'm using finally worked but the problem is that when the states overlap you can't grab each one. I attached the code and and the file. I thought about using a rigid body but that could cause issues considering it's supposed to be online. Maybe it's not even the right code for it to work properly?

extends Sprite

var dragging = false

var status = "none"
var tsize=Vector2()
var offset=Vector2()
var mpos=Vector2()

func ready():

func process(delta):
if status == "clicked":
global_pos(mpos + offset)

func input(ev):
if ev.type == InputEvent.MOUSE
if ev.buttonindex == BUTTONLEFT:
if ev.ispressed() and _isclicked(ev.globalpos):
status = "clicked"
mpos =
offset = getglobalpos() - mpos
status = "released"
elif ev.type == InputEvent.MOUSEMOTION:
if status == "clicked":
mpos = get

func isclicked(pos):
var spriterect
var gpos = get
if is
spriterect = Rect2(gpos.x - tsize.x/2, gpos.y - tsize.y/2, tsize.x, tsize.y)
rect = Rect2(gpos.x, gpos.y, tsize.x, tsize.y)

if sprite_rect.has_point(pos):
   return true

the game

1 Answer

0 votes

Those existing answers may be useful:

You may have a look at the pickable property in your collision object, which allows bodies or areas to receive input like GUI controls.

by (29,360 points)

I got it work Yay, I think it had to do with some indentation issues! The only weird thing that happens is that it sometimes picks multiple objects at once.

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 Frequently asked questions and 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 [email protected] with your username.