rem Make a floor
make object plain 1,100,25
xrotate object 1,90
make object collision box 1,-50,-1,-12.5,50,0,12.5,0
rem Make player 1
make object box 2,5,5,5
make object collision box 2,-2.5,-2.5,-2.5,2.5,2.5,2.5,0
rem Make player 2
make object box 3,5,5,5
make object collision box 3,-2.5,-2.5,-2.5,2.5,2.5,2.5,0
rem Start an array to hold info
type 3Dimensions
X as float
Y as float
Z as float
endtype
type Player
Position as 3Dimensions
Rotation as 3Dimensions
endtype
global dim Player(2) as Player
rem Initialise values
Player(0).Position.X=-20.0
Player(0).Position.Y=2.5
Player(0).Position.Z=0.0
Player(1).Position.X=20.0
Player(1).Position.Y=2.5
Player(1).Position.Z=0.0
rem Lock frame rate
sync on
sync rate 100
rem Start main loop
do
rem Control player 1
if keystate(30)=1
Player(0).Position.X=Player(0).Position.X-0.25
endif
if keystate(32)=1
Player(0).Position.X=Player(0).Position.X+0.25
endif
if Player(0).Position.X<-47.5
Player(0).Position.X=-47.5
endif
if Player(0).Position.X>47.5
Player(0).Position.X=47.5
endif
position object 2,Player(0).Position.X,Player(0).Position.Y,Player(0).Position.Z
if object collision(2,0)>0
dec Player(0).Position.X,get object collision x()
dec Player(0).Position.Y,get object collision y()
dec Player(0).Position.Z,get object collision z()
endif
rem Control player 2
if leftkey()=1
Player(1).Position.X=Player(1).Position.X-0.25
endif
if rightkey()=1
Player(1).Position.X=Player(1).Position.X+0.25
endif
if Player(1).Position.X<-47.5
Player(1).Position.X=-47.5
endif
if Player(1).Position.X>47.5
Player(1).Position.X=47.5
endif
position object 3,Player(1).Position.X,Player(1).Position.Y,Player(1).Position.Z
if object collision(3,0)>0
dec Player(1).Position.X,get object collision x()
dec Player(1).Position.Y,get object collision y()
dec Player(1).Position.Z,get object collision z()
endif
rem Update player positions
position object 2,Player(0).Position.X,Player(0).Position.Y,Player(0).Position.Z
position object 3,Player(1).Position.X,Player(1).Position.Y,Player(1).Position.Z
rem Update the camera
position camera Player(0).Position.X+(abs(Player(0).Position.X-Player(1).Position.X)/2),20,0-abs(Player(0).Position.X-Player(1).Position.X)
if camera position z()>-15
position camera camera position x(),camera position y(),-15
endif
point camera camera position x(),2.5,0.0
rem Update the screen
sync
rem End the main loop
loop
The camera works but the collision is screwed for some reason!