# Detecting click zone on game object (like gui.pick\_node) (SOLVED)

**URL:** <https://forum.defold.com/t/detecting-click-zone-on-game-object-like-gui-pick-node-solved/1684>\
**Category:** Questions\
**Created:** [April 26, 2016, 8:30am UTC](https://forum.defold.com/t/detecting-click-zone-on-game-object-like-gui-pick-node-solved/1684 "2016-04-26T08:30:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vtchiew](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/vtchiew/32/1062_2.png) [@vtchiew](https://forum.defold.com/u/vtchiew)\
**Post date:** [April 26, 2016, 8:30am UTC](https://forum.defold.com/t/detecting-click-zone-on-game-object-like-gui-pick-node-solved/1684/1 "2016-04-26T08:30:09Z")

</div>

Hello,

I am generating GOs via a factory onto the game scene, I would need to perform some logic on them upon getting clicked. After registering for the input event I would need to find out in the on\_input function if the click event is intended for a particular GO.

I understand that in gui we use gui.pick\_node to achieve this, is there an equivalent for GOs?

Thanks!

---

<div class="post-metadata">

**Author:** ![Andreas\_Jirenius](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/andreas_jirenius/32/114_2.png) [@Andreas\_Jirenius](https://forum.defold.com/u/Andreas_Jirenius)\
**Post date:** [April 26, 2016, 8:59am UTC](https://forum.defold.com/t/detecting-click-zone-on-game-object-like-gui-pick-node-solved/1684/2 "2016-04-26T08:59:09Z")

</div>

Hi  
there is no equivalent with gui.pick\_node but there are of course several ways to do this.  
Two easy things that pop in mind is to  
1: Check the distance between click and gameobject like this in on\_input:

```
local pos = go.get_position()
local distance = vmath.length(vmath.vector3(action.x, action.y, pos.z) - pos )
if distance < 40 then do_stuff() end -- where 40 is the radius of clickarea

```

2: Create collisionobjects on the gameobjects you want clickable and also create an “invisible” gameobject with a collisionobject that checks for collisions with the others.  
Then you could just move the invisible gameobject to the input position and recieve collision messages and handle the clicks whenever these messages occur. Edit: naah.. I would prefer the first one 😉

---

<div class="post-metadata">

**Author:** ![vtchiew](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/vtchiew/32/1062_2.png) [@vtchiew](https://forum.defold.com/u/vtchiew)\
**Post date:** [April 26, 2016, 9:32am UTC](https://forum.defold.com/t/detecting-click-zone-on-game-object-like-gui-pick-node-solved/1684/3 "2016-04-26T09:32:28Z")

</div>

> [@Andreas\_Jirenius](#):
>
> local pos = go.get\_position()  
> local distance = vmath.length(vmath.vector3(action.x, action.y, pos.z) - pos )  
> if distance \< 40 then do\_stuff() end – where 40 is the radius of clickarea

yay! got it working using (obviously) your first suggestion. Thanks a bunch!
