the simplest way ive found to detect a collision between two object with raycasts returns 1 if true
function checkCollision(objID as integer,objID2 as integer)
local width# as float
local height# as float
local depth# as float
local x# as float
local y# as float
local z# as float
local start_x# as float
local start_y# as float
local start_z# as float
local end_x# as float
local end_y# as float
local end_z# as float
local object_Hit as integer
//this checks for colliion between an object with any other object and returns its id
width#=(GetObjectMeshSizeMaxX(objID,1)-GetObjectMeshSizeMinX(objID,1))/2
height#=(GetObjectMeshSizeMaxY(objID,1)-GetObjectMeshSizeMinY(objID,1))/2
depth#=(GetObjectMeshSizeMaxZ(objID,1)-GetObjectMeshSizeMinZ(objID,1))/2
x#=getObjectWorldX(objID)
y#=GetObjectWorldY(objID)
z#=getObjectWorldZ(objID)
// calculate the start of the ray cast
start_x# = x#-width#
start_y# = y#+height#
start_z# = z#-depth#
// calculate the end of the ray cast
end_x# = x#+width#
end_y# = y#-height#
end_z# = z#+depth#
// determine which object has been hit
object_Hit = ObjectRayCast(objID2,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
endfunction object_Hit
or change this for any object returns the id of the collision object
object_Hit = ObjectRayCast(0,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
but you may be able to simplify this cast for bullets for example using a heliobject I did in another game
hit=ObjectRayCast(0,getObjectX(heliObj)-2.5,getObjectY(heliObj)-5.5,getObjectZ(heliObj)-5.0,getObjectX(heliObj)+2.5,getObjectY(heliObj)+2.5,getObjectZ(heliObj)+15)
edit when hit was greater than 0 there was a hit
not sure how you do your distance checking but agk has some great math functions at our fingertips I have this function
//*******************************************************************************************
//gets the distance between two objects passed
//*******************************************************************************************
function getDistance(objectID as integer,objectID2 as integer)
distance as float
vec1=CreateVector3(GetObjectWorldX(objectID),GetObjectWorldY(objectID),GetObjectWorldZ(objectID))
vec2=CreateVector3(GetObjectWorldX(objectID2),GetObjectWorldY(objectID2),GetObjectWorldZ(objectID2))
distance=GetVector3Distance(vec1,vec2 )
DeleteVector3(vec1)
DeleteVector3(vec2)
endfunction distance