If its just 2 spheres then its a really simple case where you can work out the distance the spheres are apart from each other and see if it is less then the combination of radius's added together.
// Project: Sphere collision
// Created: 2019-02-15
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Sphere collision" )
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 ) // since version 2.0.22 we can use nicer default fonts
sp1 = CreateObjectSphere(10,10,10) // radius is 5
sp2 = CreateObjectSphere(20,10,10) // radius is 10
SetCameraPosition(1,0,0,-80)
SetCameraLookAt(1,0,0,0,0)
do
mx# = GetrawMouseX()
my# = GetrawMouseY()
x# = Get3DVectorXFromScreen ( mx#, my# )*-GetCameraZ(1)
y# = Get3DVectorYFromScreen ( mx#, my# )*-GetCameraZ(1)
//z# = Get3DVectorZFromScreen ( mx#, my# )
z# =0
SetObjectPosition(sp2,x#,y#,z#)
Print( ScreenFPS() )
if CheckSphereCollision(sp1, 5, sp2, 10)
Print("Collision")
else
Print("No collision")
endif
Sync()
loop
// Returns 1 if the spheres are intersecting
// Sp1 is the object id for sphere 1
// r1 is the radius of sphere 1
// Sp2 is the object id for sphere 2
// r2 is the radius of sphere 2
function CheckSphereCollision(sp1 as integer, r1 as float, sp2 as integer, r2 as float)
xd# = GetObjectX(sp1) - GetObjectX(sp2)
yd# = GetObjectY(sp1) - GetObjectY(sp2)
zd# = GetObjectZ(sp1) - GetObjectZ(sp2)
dsq# = xd#*xd# + yd#*yd# + zd#*zd#
d# = pow(r1+r2,2)
if dsq# <= d# then exitfunction 1
endfunction 0
EDIT: please note I compare the square of each number as pow(a,2) is quicker than using sqrt()
Obviously, for more complex shapes then doing an object ray cast or using physics is a better way to go.