Many thanks to all of you!!!
This is what I wanted to create and use:
sync on
`Create the cube
make object cube 1, 5
`Make a plain
make object plain 2, 100, 100
rotate object 2, 90, 0, 0
`Make a sphere
make object sphere 3, 20
position object 3, 0, 10, 0
MaxDistance# = 10000.0
do
`Camera position
position camera -200, 300, -200
point camera 0, 0, 0
`Find world coordinates of mouse (use a distance that is big enough)
CDistance# = MaxDistance#
pick screen mousex(), mousey(), CDistance#
`Get vector components
cx# = get pick vector x()
cy# = get pick vector y()
cz# = get pick vector z()
`Find closest object
for i = 2 to 3
`Detect intersection
dist# = Intersect Object(i, camera position x(), camera position y(), camera position z(), camera position x() + cx#, camera position y() + cy#, camera position z() + cz#)
if dist# > 0.0 : `When it's 0, no intersection occurred
if dist# < CDistance# : `If the distance# is smaller than the current distance
CDistance# = dist#
endif
endif
next i
`Finally, position the object
cx# = camera position x() + (cx# * CDistance# / MaxDistance#)
cy# = camera position y() + (cy# * CDistance# / MaxDistance#)
cz# = camera position z() + (cz# * CDistance# / MaxDistance#)
position object 1, cx#, cy#, cz#
sync
loop
I modified it a little to adjust it to my needs, and it works like a charm.
@Culmor30: This code works also, but it is in FPS style. What I needed was to cast a ray, not poiting towards the camera positive Z axis, but in the mouse cursor direction. Ahhh, and you`re a lucky one to use Dark Physics extension. I use Newton and can only dream on using it, since I cannot afford it right now. I really like the Enhanced Animation extension also...
My problem is SOLVED! Thanks again to all of you helpful people