I'm trying to make levels while using physics and character controllers.
I need to know how to level progress with physics, since that always seems to be the problem. Right now i have a clearworld() function that gets rid of all objects,sounds,etc. and phy clear and phy end..
but when the timer runs out the error tells me that the character controller already exists.
Please help me try to figure out how to delete the physics objects correctly
Code:
` set up general properties
sync on
sync rate 60
autocam off
phy start
set camera range 0.5, 30000
hide mouse
` load our skybox
`load object "media\skybox2.x", 2
`set object light 2, 0
`set object texture 2, 3, 1
`scale object 2, 30000, 30000, 30000
`load maze
`load object "media\level1.dbo",20
`phy make rigid body static mesh 20
`color object 20,20
` create our box controller
make object box 3, 2, 5, 2
phy make box character controller 3, 0, 505, 0, 1, 1, 1, 1, 10.5, 45.0
phy set gravity 0.0,-7.0,0.0
hide object 3
`Make platforms
`Homebase()
`Platforms()
CTtimer = timer()
CTVal = 20
` our main loop
do
` display instructions
set cursor 10,390
`Make Clock
if Timer() - CTtimer => 1000
Dec CTVal
CTtimer = Timer()
EndIf
set text size 18
print "Time Remaining: ";Str$(CTVal)
If CTVal = 0
clearworld()
goto level2
endif
` rotate and position the camera based on the box controller
position camera object position x ( 3 ), object position y ( 3 ) + 5, object position z ( 3 )
rotate camera object angle x ( 3 ), object angle y ( 3 ), object angle z ( 3 )
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
CameraAngleY# = wrapvalue ( CameraAngleY# + mousemovex ( ) * 0.4 )
CameraAngleX# = wrapvalue ( CameraAngleX# + mousemovey ( ) * 0.4 )
yrotate object 3, curveangle ( CameraAngleY#, OldCamAngleY#, 24 )
xrotate object 3, curveangle ( CameraAngleX#, OldCamAngleX#, 24 )
` react to key presses and move the controller
key = 0
if spacekey() = 1
move object up 3,20
endif
if upkey ( )
key = 1
phy move character controller 3, 20.0
endif
if downkey ( )
key = 1
phy move character controller 3, -20.0
endif
if key = 0
phy move character controller 3, 0.0
endif
` update the simulation and screen
phy update
sync
loop
`==========================================================
`==========================================================
`==========================================================
level2:
` set up general properties
sync on
sync rate 60
autocam off
phy start
set camera range 0.5, 30000
hide mouse
` load our skybox
load object "media\skybox2.x", 2
set object light 2, 0
set object texture 2, 3, 1
scale object 2, 30000, 30000, 30000
`load maze
load object "media\level1.dbo",20
phy make rigid body static mesh 20
color object 20,20
` create our box controller
make object box 3, 2, 5, 2
phy make box character controller 3, 0, 505, 0, 1, 1, 1, 1, 10.5, 45.0
phy set gravity 0.0,-7.0,0.0
hide object 3
`Make platforms
`Homebase()
`Platforms()
CTtimer = timer()
CTVal = 10
` our main loop
do
` display instructions
set cursor 10,390
`Make Clock
if Timer() - CTtimer => 1000
Dec CTVal
CTtimer = Timer()
EndIf
set text size 18
print "Time Remaining: ";Str$(CTVal)
If CTVal = 0
clearworld()
end
endif
` rotate and position the camera based on the box controller
position camera object position x ( 3 ), object position y ( 3 ) + 5, object position z ( 3 )
rotate camera object angle x ( 3 ), object angle y ( 3 ), object angle z ( 3 )
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
CameraAngleY# = wrapvalue ( CameraAngleY# + mousemovex ( ) * 0.4 )
CameraAngleX# = wrapvalue ( CameraAngleX# + mousemovey ( ) * 0.4 )
yrotate object 3, curveangle ( CameraAngleY#, OldCamAngleY#, 24 )
xrotate object 3, curveangle ( CameraAngleX#, OldCamAngleX#, 24 )
` react to key presses and move the controller
key = 0
if spacekey() = 1
move object up 3,20
endif
if upkey ( )
key = 1
phy move character controller 3, 20.0
endif
if downkey ( )
key = 1
phy move character controller 3, -20.0
endif
if key = 0
phy move character controller 3, 0.0
endif
` update the simulation and screen
phy update
sync
loop
`Start Area
Function HomeBase()
make object box 1,20,2,20
color object 1,rgb(0,255,120)
phy make rigid body static mesh 1
EndFunction
`===========================================================
`Set up Boxes
Function Boxes(objnum,xsize,zsize,xpos,ypos,zpos)
make object box objnum,xsize,2,zsize,
position object objnum,xpos,ypos,zpos
phy make rigid body static mesh objnum
EndFunction
`===========================================================
`Make Platforms
Function Platforms()
Boxes(10,30,30,60,5,10)
EndFunction
`===========================================================
`EndLevel
Function EndLevel()
If CTVal = 0 then end
EndFunction
`===========================================================
`ClearWorld
Function Clearworld()
for x = 1 to 1000
if object exist(x) then delete object x
if sound exist(x) then delete sound x
if sprite exist(x) then delete sprite x
phy delete rigid body x
phy clear
phy end
next x
EndFunction
* I REMed out the .dbo and skybox... since they arent neccessary