Detecting click zone on game object (like gui.pick_node) (SOLVED)

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!

1 Like

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 :wink:

6 Likes

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

2 Likes