Hi there . This is an old code I made some time ago . The famous AABB collision but working in a 3D scene . The only requirement is that the objects must not be rotated . I hope this code can be useful . For future updates , will be put in my Chafari tricks thread .
// Project: AABB collision
// Created: 2019-02-28
// show all errors
SetErrorMode(2)
SetRawMouseVisible(0)
// set window properties
SetWindowTitle( "AABB collision" )
SetWindowSize( 1024, 768, 0 ) // MODO 1 PARA FULL SCREEN
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( 60, 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
loadimage(10,"bunker.png")
loadimage(2,"wall.jpg")
loadimage(3,"sand.png")
loadimage(4,"stone.png")
loadimage(5,"wood.png")
loadimage(6,"crater.jpg")
`floor and stairs
createobjectbox(1,350,1,350)
setobjectposition(1,0,1,0)
//setobjectcolor(1,100,70,30,0)
setobjectimage(1,3,0)
`steps
for i= 2 to 30
createobjectbox(i,10,1,3)
setobjectposition(i,0,i,i+i*2)
//setobjectcolor(i,200,200,0,0)
setobjectimage(i,5,0)
SetObjectCastShadow( i, 1 )
next
`second floor
setobjectposition(30,0,getobjecty(30),126)
SetObjectScalePermanent(30,5,1,25)
`sensor to go up/down stairs
createobjectbox(100,4,4,4)
SetObjectVisible(100,0)
`player
createobjectcapsule(101,3,6,4) `7777777777777777777777777777777
createobjectsphere(102,2,10,10)
FixObjectToObject(102,101)
setobjectposition(102,0,2,0)
fixobjectpivot(102)
setobjectcolor(101,0,200,0,0)
setobjectcolor(102,0,200,0,0)
setobjectscale(102,1,2,1)
fixobjectpivot(102)
SetObjectCastShadow( 101, 1 )
SetObjectCastShadow( 102, 1 )
SetObjectVisible(102,0)
`Blocks ))))))))))))))))))))))))))))))))))))))))))))))))))))))
createobjectbox(201,50,20,20)
setobjectposition(201,-30,8,110)
setobjectimage(201,10,0)
SetObjectCastShadow( 201, 1 )
cloneobject(202,201)
setobjectposition(202,60,8,80)
cloneobject(203,201)
setobjectposition(203,40,10,-10)
setobjectrotation(203,0,90,0)
fixobjectpivot(203)
createobjectbox(204,1,14,75)
setobjectposition(204,0,10,126)
fixobjectpivot(204)
setobjectposition(204,25,27,0)
setobjectcolor(204,255,255,255,0)
setobjectimage(204,2,0)
fixobjectpivot(204)
//cloneobject(205,204)
createobjectbox(205,1,14,75)
setobjectposition(205,-25,37,126)
setobjectimage(205,2,0)
fixobjectpivot(205)
createobjectbox(206,50,15,1)
setobjectimage(206,2,0)
setobjectposition(206,0,37,163)
fixobjectpivot(206)
createobjectbox(207,5,15,10)
setobjectimage(207,4,0)
setobjectposition(207,-40,7.5,20)
fixobjectpivot(207)
cloneobject(208,207)
setobjectposition(208,5,8.5,0)
fixobjectpivot(208)
cloneobject(209,207)
setobjectposition(209,10,0,0)
createobjectbox(210,10,10,10)
setobjectrotation(210,10,40,10)
setobjectposition(210,0,0,-30)
fixobjectpivot(210)
setobjectimage(210,4,0)
createobjectbox(211,8,8,8)
setobjectposition(211,-15,34,150)
setobjectrotation(211,0,20,0)
fixobjectpivot(211)
setobjectimage(211,6,0)
loadobject(212,"supermario.x")
setobjectscale(212,0.2,0.2,0.2)
setobjectposition(212,-30,16,-20)
setobjectimage(212,4,0)
fixobjectpivot(212)
createobjectbox(213,8,8,8)
setobjectposition(213,-15,34,140)
setobjectimage(213,6,0)
fixobjectpivot(213)
cloneobject(214,213)
setobjectposition(214,0,8,5)
`sky
createobjectsphere(1000,1000,8,8)
SetObjectColorEmissive(1000,0,0,255)
SetObjectCullMode(1000,0)
`camera
setcameraposition(1,-80,80,-80)
SetCameraLookAt(1,0,15,25,0)
tn#=90
y#=2
z#=-10
`Shadow setup
shadowMode = 3 // start with cascade shadow mapping which gives the best quality
SetShadowMappingMode( shadowMode )
SetShadowSmoothing( 2 ) // random sampling
SetShadowMapSize( 1024, 1024 )
SetShadowRange( -1 ) // use the full camera range
SetShadowBias( 0.0012 ) // offset shadows slightly to avoid shadow artifacts
`Sun setup
dx# = -1.3714
dy# = -1.1428
dz# = 0.5571
SetSunDirection( dx#, dy#, dz# )
t=0
SetCameraFOV(1,90)
SetRawMousePosition(512,384)
do
z1#=getobjectz(100)
x1#=getobjectx(100)
y1#=getobjecty(100)
oldx#=x#
oldz#=z#
maxz1#=GetObjectMeshSizeMaxZ(100,1)
minz1#=GetObjectMeshSizeMinZ(100,1)
maxx1#=GetObjectMeshSizeMaxx(100,1)
minx1#=GetObjectMeshSizeMinx(100,1)
maxy1#=GetObjectMeshSizeMaxy(100,1)
miny1#=GetObjectMeshSizeMiny(100,1)
if ( GetRawKeyState( 38 ) )
x#=x#+(cos(tn#))*0.6
z#=z#+(sin(tn#))*0.6
endif
if ( GetRawKeyState( 40 ) )
x#=x#+(cos(tn#))*-0.6
z#=z#+(sin(tn#))*-0.6
endif
`- Strafe right
if ( GetRawKeyState( 39 ) )
x#=x#+(cos(tn#-90))*0.3
z#=z#+(sin(tn#-90))*0.3
endif
`- Strafe left
if ( GetRawKeyState( 37 ) )
x#=x#+(cos(tn#+90))*0.3
z#=z#+(sin(tn#+90))*0.3
endif
if ( GetRawKeyState( 27) ) then end //exit with escapakey
if ( GetRawKeyState( 32) ) then end //exit with spacekey
setobjectposition(100,x#,y#,z#)
tn#=-80-getpointerx()
`stairs collision ------------------------------------------------------------------------------
for i= 1 to 30
sx#=getobjectx(i)
sy#=getobjecty(i)
sz#=getobjectz(i)
maxz2#=GetObjectMeshSizeMaxZ(i,1)
minz2#=GetObjectMeshSizeMinZ(i,1)
maxx2#=GetObjectMeshSizeMaxx(i,1)
minx2#=GetObjectMeshSizeMinx(i,1)
maxy2#=GetObjectMeshSizeMaxy(i,1)
miny2#=GetObjectMeshSizeMiny(i,1)
if x1#+maxx1#>sx#-maxx2# and x1#+minx1#< sx#+maxx2# and z1#+maxz1#>sz#-maxz2# and z1#+minz1#< sz#+maxz2# and y1#+maxy1#>sy#-maxy2# and y1#+miny1#< sy#+maxy2# then tt=1 else tt=0
if tt>0 then setobjectposition(100,x#,getobjecty(i),z#)
next
setobjectposition(101,getobjectx(100),getobjecty(100)+2,getobjectz(100))
setobjectrotation(101,0,-tn#,0)
`Blocks collision `-----------------------------------------------------------------------------
for t= 201 to 214
//setobjectimage(t,10,0)
SetObjectCastShadow( t, 1 )
maxz2#=GetObjectMeshSizeMaxZ(t,1)
minz2#=GetObjectMeshSizeMinZ(t,1)
maxx2#=GetObjectMeshSizeMaxx(t,1)
minx2#=GetObjectMeshSizeMinx(t,1)
maxy2#=GetObjectMeshSizeMaxy(t,1)
yy#=getobjecty(100)
z1#=getobjectz(1)
x1#=getobjectx(1)
y1#=getobjecty(1)
z2#=getobjectz(t)
x2#=getobjectx(t)
y2#=getobjecty(t)
if z#+maxz1#>z2#+minz2# and oldx#+maxx1#>x2#+minx2# and oldx#+minx1# <x2#+maxx2# and z#+minz1#<z2#+maxz2# and abs(yy#-maxy2#)<20
z#=oldz#
endif
if oldz#+maxz1#>z2#+minz2# and x#+maxx1#>x2#+minx2# and x#+minx1# <x2#+maxx2# and oldz#+minz1#<z2#+maxz2# and abs(yy#-maxy2#)<20
x#=oldx#
endif
next
rota=getpointery()
if rota<330 then rota=330
if rota>420 then rota=420
if rota<331 then SetRawMousePosition( getpointerx(), 330 )
setcameraposition(1,getobjectx(100),getobjecty(100)+5,getobjectz(100))
setcamerarotation(1,rota,GetObjectAngleY(100)+90,0)
setobjectrotation(100,0,-tn#,0)
Print( ScreenFPS() )
print("")
print(getcamerax(1))
print(getcameray(1))
print(getcameraz(1))
print(GetCameraAngleX(1))
print(getpointery())
kja=getpointerx()
print ("x "+str(kja))
if getpointerx()<2 then SetRawMousePosition(722,getpointery())
if getpointerx()>1022 then SetRawMousePosition(660,getpointery())
Sync()
loop
I'm not a grumpy grandpa