Here's some sample code (slightly modified example from the documentation) using the FPSC stock model Swat.X (attached), which I think clearly demonstrates the problem. Change the LoadObjectWithChildren to LoadObject, and you'll notice it works perfectly.
//Raycast Test
SetWindowTitle( "Raycast Test" )
SetWindowSize( 1024, 768, 0 )
SetSyncRate( 60, 0 )
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
LoadObjectWithChildren(1, "Swat.X")
SetObjectCollisionMode(1, 1)
SetObjectPosition(1, 0, -35, 0)
// create a blue sphere to use as a marker object (this will show the position of the ray cast intersect)
CreateObjectSphere(2,5,12,12)
SetObjectColor(2,0,0,255,255)
// create a green sphere to show the start point of the ray cast
CreateObjectSphere(3,5,12,12)
SetObjectColor(3,0,255,0,255)
SetObjectPosition(3,-20,45,-20)
// create a red sphere to show the start point of the ray cast
CreateObjectSphere(4,5,12,12)
SetObjectColor(4,255,0,0,255)
SetObjectPosition(4,20,45,20)
// Position and orientate camera
SetCameraPosition(1,0,0,-100)
SetCameraLookAt(1,0,0,0,0)
// main loop
do
// get player input
joystick_y# = GetJoystickY()*-1
joystick_x# = GetJoystickX()*-1
// move green and red spheres
MoveObjectLocalY(3,joystick_y#)
MoveObjectLocalY(4,joystick_y#)
MoveObjectLocalX(3,-joystick_x#)
MoveObjectLocalX(4,joystick_x#)
// raycast from the green sphere to the red sphere
old_x# = GetObjectX(3)
old_y# = GetObjectY(3)
old_z# = GetObjectZ(3)
new_x# = GetObjectX(1)
new_y# = old_y#//0.5//GetObjectY(1)
new_z# = GetObjectZ(1)
object_hit = ObjectRayCast(1,old_x#,old_y#,old_z#,new_x#,new_y#,new_z#)
print(object_hit)
// ray cast against object 1 only
if object_hit <> 0
// get the ray cast intersect point
intersect_x# = GetObjectRayCastX(0)
intersect_y# = GetObjectRayCastY(0)
intersect_z# = GetObjectRayCastZ(0)
// set the position of the blue sphere to the intersect point
SetObjectPosition(2,intersect_x#,intersect_y#,intersect_z#)
// make the blue sphere visible
SetObjectVisible(2,1)
else
// if the ray cast does not intersect the box then hide the blue sphere
SetObjectVisible(2,0)
endif
sync()
loop