Hi there.
What about instead of using raycasting, use GetScreenXFrom3D /GetScreenYFrom3D to detect what object has being clicked ? something like this :
// Project: Object Clicked
// Created: 2019-01-19
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Object Clicked" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
for i= 1 to 20
createobjectbox(i,2,2,2)
setobjectposition(i,0-30+random(0,60),0-30+random(0,60),-30+random(0,60))
next
setcameraposition(1,-30,30,-100)
SetCameraLookAt(1,0,0,0,0)
sel=0
do
g=g+3
for i= 1 to 20
x#=getobjectx(i)
y#=getobjecty(i)
z#=getobjectz(i)
px = GetScreenXFrom3D( x#,y#,z#)
py = GetScreenYFrom3D( x#,y#,z#)
if GetRawMouseleftState()=1 and px-8<getpointerx() and px+8 >getpointerx() and py-8<getpointery() and py+8 >getpointery()then sel=i
next
if sel>0 then setobjectrotation(sel,0,g,0)
for i= 1 to 20
SetObjectColor(i,0,255,0,0)
next
if sel>0 then SetObjectColor(sel,255,0,0,0)
`desseleccionamos todo
if GetRawMouserightState()=1 then sel=0
Print( ScreenFPS() )
print("Object Clicked "+str(sel))
Sync()
loop
I'm not a grumpy grandpa