This should do the trick i think. It gives you the object under the mouse position.
If you want a particular point then change references to GetPointerX() and GetPointerY() to your x and y values
The 10000 value is the distance from the camera that it will check so if your environment is larger, increase that value
type tPoint
x as float
y as float
z as float
endtype
function GetHitID()
f as tPoint
t as tPoint
w as tPoint
dot as float
r as integer
id as integer
f.x = Get3DVectorXFromScreen( GetPointerX(), GetPointerY() )
f.y = Get3DVectorYFromScreen( GetPointerX(), GetPointerY() )
f.z = Get3DVectorZFromScreen( GetPointerX(), GetPointerY() )
// get a vector that points in the direction the camera is looking
t.x = Get3DVectorXFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
t.y = Get3DVectorYFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
t.z = Get3DVectorZFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
// normalise Vector in the direction of Vector2
dot = f.x*t.x + f.y*t.y + f.z*t.z
if ( dot > 0 )
f.x = f.x / dot
f.y = f.y / dot
f.z = f.z / dot
endif
w.x = f.x * 10000 + GetCameraX(1)
w.y = f.y * 10000 + GetCameraY(1)
w.z = f.z * 10000 + GetCameraZ(1)
ObjectRayCast(0, GetcameraX(1), GetcameraY(1), GetcameraZ(1), w.x, w.y, w.z)
if GetObjectRayCastNumHits() > 0
id = GetObjectRayCastHitID(0)
endif
endfunction id