That does produce strange results for me also. On a side note, in case anyone else might want to accomplish the same kind of thing, here is an approach that just involves performing a ray cast directly, then retrieving the contact point and normals (based on the same code, just with the physics command set remmed out and replaced):
// Project: raycast
// Created: 21-04-30
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "raycast" )
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 )
` Create3DPhysicsWorld(4)
ground = CreateObjectBox(20, 1, 20)
` Create3DPhysicsStaticBody(ground)
` raycast = Create3DPhysicsRay()
fromVec = CreateVector3()
toVec = CreateVector3()
` contactVec = CreateVector3()
` normalVec = CreateVector3()
ResetAndTryAgain:
SetVector3(fromVec, 0, 5, 0)
SetVector3(toVec, 0, -1, 0)
` RayCast3DPhysics(raycast, fromVec, toVec, 0)
` Get3DPhysicsRayCastClosestContactPosition(raycast, contactVec)
` Get3DPhysicsRayCastNormalVector(raycast, normalVec)
s=ObjectRayCast(ground,GetVector3X(fromVec),GetVector3Y(fromVec),GetVector3Z(fromVec),GetVector3X(toVec),GetVector3Y(toVec),GetVector3Z(toVec))
if s<>0
ContactX#=GetObjectRayCastX(0)
ContactY#=GetObjectRayCastY(0)
ContactZ#=GetObjectRayCastZ(0)
NormalX#=GetObjectRayCastNormalX(0)
NormalY#=GetObjectRayCastNormalY(0)
NormalZ#=GetObjectRayCastNormalZ(0)
endif
do
` Print( "contact: " + str(GetVector3X(contactVec)) + ", " + str(GetVector3Y(contactVec)) + ", " + str(GetVector3Z(contactVec)))
` Print( "normal: " + str(GetVector3X(normalVec)) + ", " + str(GetVector3Y(normalVec)) + ", " + str(GetVector3Z(normalVec)))
Print( "contact: " + str(ContactX#) + ", " + str(ContactY#) + ", " + str(ContactZ#))
Print( "normal: " + str(NormalX#) + ", " + str(NormalY#) + ", " + str(NormalZ#))
Sync()
if GetRawKeyState(32)>0
goto ResetAndTryAgain
endif
if GetRawKeyState(27)>0 then end
loop
You can optionally press the spacebar to re-run the collision check.