How to implement merge mechanics

I’m trying with checking trigger response when two go with similar sprite drag one on top of another and to instance to another go. But with attached script on item go it will call two times due to both item game objects have same script attached. (Need info how to do merge mechanics with go)

1 Like

You could have one central controller script that handles the merging. Instead of the game objects doing the merging themselves, they would send a message to the central script. The central script would have logic to prevent duplicates.

3 Likes

Also remember you have access to the other_id from the collision message:
Collision messages in Defold, so you could use that to check if it’s already has been triggered and prevent a duplicate in your game logic.

3 Likes

You may benefit from Defold-Input - the drag handling is pretty useful for this situation.

2 Likes

Thanks. I did implemented the merge properly. Obviously code quality will be bad.

Now I wanted my items(apples) to drag in land area only when its drag to sky area I want it to fall down to land area.

Project file -
Merge.zip (1.5 MB)

Do you have a question? What have you tried so far?

We are here to help, but that is primarily to enable you to gain enough knowledge to do things yourself.

3 Likes

This what I have done item(apple) is falling down but I have no idea how to make it draggable in land area.

There are many ways to achieve something like this. It’s hard to provide suggestions without understanding what you’ve done so far, so you’ll need to explain it.

So the item(apple) has kinematic collision with script to handle gravity. And land area with static collision shape. Now I don’t have any solution/idea how to make this item draggable in land area. I already googled “pickup and placing objects”, “drag and drop objects with gravity” in unity to take some ideas but so far no solution.

Did you look at the code for handling dragging of game objects in Defold-Input?

2 Likes