Mouse Click through invisible Object

From my knowledge, to perform a click action to an object
we need to detect the mouse click action and mouse over position

and now i am facing a problem that if the object “is blocked” by an invisible object
i cannot get the correct mouse over, it always get the object that is in front but invisible

how can i click the object through some invisible objects?

I have attached a blend

there are two cubes and one plane
cube02 is just in front of cube01
cube02 is set to be invisible when running
both of the cubes have the same logic bricks


cont = bge.logic.getCurrentController()mouse = cont.sensors['Mouse2']
if cont.owner.visible == True:
    print (mouse.hitObject)

my expectation is when mouse cursor is moved to the cube01 (any parts)
console window will print “cube01”

however, now if the mouse cursor is moved to the front part of the cube01 (which is supposed blocked by the invisible cube02), console window print nothing

then I change the python to


cont = bge.logic.getCurrentController()
mouse = cont.sensors['Mouse2']
print (mouse.hitObject)

similar result
but another problem i found:
if the mouse cursor directly enter the cube02 (from bottom to upward), console window output cube02 as expected
but if the mouse cursor first enter the cube01 then cube02 (from upward to bottom), the console window output cube01 cube02 none

how can i perform the click on cube01 if cube02 is invisible but click on cube02 if cube02 is visible?
Thank you.

mouseclick.blend (503 KB)

use a ray cast from camera @ mouse click position (not object) mouse.hitPosition
cast past the hit position?
make sure the ray is X-ray

:smiley:

you may have to sort through a list returned by the ray?

The reason for this is that raycasting uses the Physics system. In order for this to work, it needs to be able to pass through the object, so you need to set the object physics type to None/Ghost

thanks for help
can you say more detail on ray please

i am very weak on using it.

What is “target”?

you should be casting from the camera PAST the point mouse.hit Position

which will require some math.

and mosue.hitObject() is a list I believe ?

no?
as i

print (mouse.hitObject)

it only output an object

here ya go,

you were casting the ray from mouse.hitPosition to the camera (backwards!) and you had the distance set to 0,

(the amount it checks PAST the last point)

and you needed X ray on, and you need a property to check for, like “Bob” in this instance

:smiley:

Attachments

mouseclick.blend (448 KB)

If it is invisible … why is it still there?

I am not sure why he needs the invisable cubes, but I have wanted to do something similar before,

here is a slightly better example

note the debug property and the blue ray,

Change the camera off camera and try it out again

the red ray is the cast without the distance added,

the blue ray goes from the mouse.hitPosition to the ray[0] if its not none

perhaps he has some alpha mapped FX that are getting in the way of his ray cast?
:smiley:

Attachments

mouseSlick.blend (524 KB)