# How to implement merge mechanics

**URL:** <https://forum.defold.com/t/how-to-implement-merge-mechanics/70773>\
**Category:** Questions\
**Created:** [April 24, 2022, 5:44am UTC](https://forum.defold.com/t/how-to-implement-merge-mechanics/70773 "2022-04-24T05:44:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikash](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/vikash/32/22674_2.png) [@vikash](https://forum.defold.com/u/vikash)\
**Post date:** [April 24, 2022, 5:44am UTC](https://forum.defold.com/t/how-to-implement-merge-mechanics/70773/1 "2022-04-24T05:44:51Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Alex\_8BitSkull](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alex_8bitskull/32/5424_2.png) [@Alex\_8BitSkull](https://forum.defold.com/u/Alex_8BitSkull)\
**Post date:** [April 24, 2022, 9:40am UTC](https://forum.defold.com/t/how-to-implement-merge-mechanics/70773/2 "2022-04-24T09:40:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jonas.sandstedt](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jonas.sandstedt/32/16136_2.png) [@jonas.sandstedt](https://forum.defold.com/u/jonas.sandstedt)\
**Post date:** [April 24, 2022, 10:29am UTC](https://forum.defold.com/t/how-to-implement-merge-mechanics/70773/3 "2022-04-24T10:29:14Z")

</div>

Also remember you have access to the `other_id` from the collision message:  
[Collision messages in Defold](https://defold.com/manuals/physics-messages/), so you could use that to check if it’s already has been triggered and prevent a duplicate in your game logic.

---

<div class="post-metadata">

**Author:** ![AarrrBee](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aarrrbee/32/24978_2.png) [@AarrrBee](https://forum.defold.com/u/AarrrBee)\
**Post date:** [April 25, 2022, 3:35pm UTC](https://forum.defold.com/t/how-to-implement-merge-mechanics/70773/4 "2022-04-25T15:35:08Z")

</div>

You may benefit from [Defold-Input](https://defold.com/assets/defoldinput/) - the drag handling is pretty useful for this situation.

---

<div class="post-metadata">

**Author:** ![vikash](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/vikash/32/22674_2.png) [@vikash](https://forum.defold.com/u/vikash)\
**Post date:** [April 30, 2022, 5:13am UTC](https://forum.defold.com/t/how-to-implement-merge-mechanics/70773/5 "2022-04-30T05:13:32Z")

</div>

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

 ![Screenshot from 2022-04-30 10-14-08](https://forum-defold-uploads.b-cdn.net/original/3X/9/a/9a61705fa8737d1434f6aba9ea25723391e95595.jpeg)

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](https://forum.defold.com/uploads/short-url/qsctUrSUeZqbdS6QvRFcRNgSfK5.zip) (1.5 MB)

---

<div class="post-metadata">

**Author:** ![Alex\_8BitSkull](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alex_8bitskull/32/5424_2.png) [@Alex\_8BitSkull](https://forum.defold.com/u/Alex_8BitSkull)\
**Post date:** [April 30, 2022, 6:19am UTC](https://forum.defold.com/t/how-to-implement-merge-mechanics/70773/6 "2022-04-30T06:19:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vikash](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/vikash/32/22674_2.png) [@vikash](https://forum.defold.com/u/vikash)\
**Post date:** [April 30, 2022, 7:22am UTC](https://forum.defold.com/t/how-to-implement-merge-mechanics/70773/7 "2022-04-30T07:22:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Alex\_8BitSkull](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alex_8bitskull/32/5424_2.png) [@Alex\_8BitSkull](https://forum.defold.com/u/Alex_8BitSkull)\
**Post date:** [April 30, 2022, 8:36am UTC](https://forum.defold.com/t/how-to-implement-merge-mechanics/70773/8 "2022-04-30T08:36:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vikash](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/vikash/32/22674_2.png) [@vikash](https://forum.defold.com/u/vikash)\
**Post date:** [April 30, 2022, 9:18am UTC](https://forum.defold.com/t/how-to-implement-merge-mechanics/70773/9 "2022-04-30T09:18:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [April 30, 2022, 3:08pm UTC](https://forum.defold.com/t/how-to-implement-merge-mechanics/70773/10 "2022-04-30T15:08:48Z")

</div>

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