Hi there .....I was going to add this example in Game_Code_here thread but I think a new one would be more visible for other users . It is a basic collision system where you can go up & down in terrains or levels made in any 3D editor....we have to use cursor and mouse to move and look around . I hope you can find it useful .
// Project: COLISIONES de upv
// Created: 2019-03-22
// 30 Abril 2021 actualizado MouseLook
// show all errors
SetErrorMode(2)
SetRawMouseVisible(0)
// set window properties
SetWindowTitle( "COLISIONES de upv" )
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
createobjectbox(1,300,50,1)
setobjectposition(1,0,25,150)
cloneobject(2,1)
setobjectposition(2,0,25,-150)
cloneobject(3,1)
setobjectposition(3,-150,25,0)
setobjectrotation(3,0,90,0)
fixobjectpivot(3)
cloneobject(4,3)
setobjectposition(4,300,0,0)
createobjectbox(5,300,1,300)
createobjectbox(6,150,1,50)
setobjectposition(6,25,34,94.3)
loadimage(1,"bunker.jpg")
loadimage(2,"madera.png")
loadimage(3,"test.png")
loadimage(4,"madera2.png")
for i= 1 to 6
setobjectimage(i,1,0)
next
setobjectimage(6,4,0)
o=0
for i= 7 to 23
inc o,1.5
createobjectbox (i,20,0.6,5)
setobjectposition(i,90,o,-1.2+o*2)
setobjectimage(i,2,0)
next
loadobject(50,"arbolsm.x")
setobjectimage(50,3,0)
setobjectscale(50,10,10,10)
setobjectposition(50,2,0,0)
for i= 51 to 53
cloneobject(i,50)
next
setobjectposition(51,-116,0,-113)
setobjectrotation(51,0,80,0)
setobjectscale(51,10,13,10)
setobjectposition(52,116,0,90)
setobjectrotation(52,0,180,0)
setobjectposition(53,-58,0,89)
setobjectrotation(53,0,-90,0)
createobjectbox(54,70,1,70)
setobjectimage(54,2,0)
setobjectposition(54,getobjectx(51),34,getobjectz(51))
createobjectbox(55,100,0.5,20)
setobjectposition(55,-35,18,-138)
setobjectrotation(55,0,0,-20)
setobjectimage(55,4,0)
CreateObjectCylinder(56,35,8,12)
setobjectposition(56,-7,16,92)
setobjectimage(56,1,0)
cloneobject(57,56)
setobjectposition(57,57,16,92)
`Lift
createobjectbox(70,25,1,25)
setobjectposition(70,-15,1,57)
setobjectimage(70,2,0)
`terrain object
loadobject(77,"terrenop.x")
loadimage(77,"sand.png")
setobjectimage(77,77,0)
setobjectposition(77,-140,-60,140)
setobjectscale(77,2,1,2)
setobjectrotation(77,10,0,0)
`Sky object
createobjectsphere(1000,2000,10,0)
SetObjectCullMode(1000,0)
SetObjectColorEmissive(1000,0,0,255)
setcameraposition(1,50,50,100)
SetCameraLookAt(1,0,0,0,0)
setcamerarange(1,0.1,10000)
SetRawMousePosition(512,384)
SetRawMousePosition(1024/2,768/2)
li#=0
do
inc li#,0.2
if li#<33 then MoveObjectLocalY(70,0.2)
if li#>50 and getobjecty(70)>2 then MoveObjectLocalY(70,-0.2)
if li#>102 then li#=0
rem Old position
oldx#=GetCameraX(1)
oldy#=GetCameraY(1)
oldz#=GetCameraZ(1)
`
rem Move camera
if ( GetRawKeyState( 38 ) ) then MoveCameraLocalZ( 1, 3 )
if ( GetRawKeyState( 40 ) ) then MoveCameraLocalZ( 1, -3 )
if ( GetRawKeyState( 37 ) ) then MoveCameraLocalX( 1, -3 )
if ( GetRawKeyState( 39 ) ) then MoveCameraLocalX( 1, 3 )
//if ( GetRawKeyState( 32 ) ) then end
if ( GetRawKeyState( 27 ) ) then end
rem Gravity on camera
SetCameraPosition(1,getcamerax(1),getcameray(1)-3,getcameraz(1))
//SetPointLightPosition(1,getcamerax(1),getcameray(1),getcameraz(1))
rem New position
newx#=GetCameraX(1)
newy#=GetCameraY(1)
newz#=GetCameraZ(1)
`
rem Adjust Y to match floor
if ObjectSphereSlide(0,oldx#,oldy#,oldz#,newx#,newy#,newz#,10)>0
newx#=GetObjectRayCastSlideX(0)
newy#=GetObjectRayCastSlideY(0)
newz#=GetObjectRayCastSlideZ(0)
SetCameraPosition(1,newx#,newy#,newz#)
endif
turn=getpointery()
if turn<330 then turn=330
if turn>420 then turn=420
if turn<331 then SetRawMousePosition( getpointerx(), turn )
if turn>421 then SetRawMousePosition( getpointerx(), turn )
if getpointerx()<100 then SetRawMousePosition(460,getpointery())
if getpointerx()>700 then SetRawMousePosition(340,getpointery())
setcamerarotation(1,turn,getpointerx(),0)
rem SetPointLightPosition(1,getcamerax(1),getcameray(1),getcameraz(1))
Print( ScreenFPS() )
print(getcamerax(1))
print(getcameray(1))
print(getcameraz(1))
Sync()
loop
I'm not a grumpy grandpa