How to make something dragable?

Godot Version

4.6

Question

Helloooooooooo!

I have a few sprites I would like to be able to drag and drop onto each other to make them interact/play animations. How do i make it so you can drag-and-drop them and have it interact with each other if you combine the right ones?

1 Like

To be clear, this is 2D right? Not 3D

2 Likes

Well thier is a way. By adding a collision shape and in inspector of collision shape set the pick able opretion.. and in script set a method any like by name of Sprite..

In mon game logic script set logic by collision area signals..

On collision.. if the body has the method that you set in and then it will Play the animation.. else do nothing..

Well i don’t know I get your problem or not but i think is a good solution to play animation when one object enter in collision area of other..

And sorry if you don’t get.. because i am poor at explaining :sweat_smile::sweat_smile:

1 Like

Yep :smiley:

i just need to be able to combine three things, so i dont think it can be an on_body_entered thing.

I need it to be able to tell if two things are colliding, and then if another object enters the area where those things are colliding

1 Like

would something like

func on body entered

if body entered (whatever it would be)

Would that work? becauseit would check if a specific body entered and then check if another specific body entered right? (i know its not in the correct format but its also not code i pasted from my editor :3)

1 Like

How would i make it have a method? :smiley:

1 Like

Well that is little easy .. in the script of that object for example you have a object name tomato, cabbage and cheeze and bread to mke sandwich..

So in scripts of Tomato, cabbage cheese and bread.. make function like on Tomato make function tomato

Func Tomato (): pass

And in script of cabbage. Add function

Func cabbage(): pass

In script cheese add function cheese..

Func cheese(): pass 

In script of breads add function breads..

Func bread(): pass 

These are the methods created…

And then assign them collision shapes.. and in Main script connect all the. “areas body enter signals “.. and like

Func on_area_body_entered():                            if body.has_meathod(" tomato, cabbage, cheese, bread"):  burger.visible = true 

Well i am writing this on mobile so sorry for synthex confusion.. i don’t have my laptop right now for some reasons :sweat_smile:..

Well if you want separately.. then you can connect separate signals..

Like :—

Func on_area_body_entered():   the area signals form bread..   if body.has_method("cabbage"):                 bread_with_cabbage_image.visible = true 

Hope so it’s helpful… if you provide more information then might be we could find any other better way :blush:

I think i know how to make this but don’t know how to explain :disappointed_face:.. because I am Also working on similar system of collision.. so i have a little much idea…

For checking multiple things you can use “AND” keyboard.. like example:—

Func on_area_body_ebtered(): if body.has_method("burger") and body.has_method("mouth"): eating_animation.play()

With use of “OR” and “AND” keywords we can set multiple condition under one function. In AND it’s compulsary that all conditions should match and in OR if any one condition is matching then it will execute codes.. ..

Hope so it’s helpful :blush:

Start by implementing only the drag first, which is simpler. Once you have that, it’ll inform you on how to implement drop.

3 Likes

SO i enabled pickable, what do i do for draggable?

There’s no checkbox. You’ll need to code it. Start by detecting clicks.