I have a first person collision code and i'd like to make it to when i press the key "v" it changes to third person. Then when i press "v" again it changes back to first person. Is there a way to do this. Here is some of my code broken down:
If UseReticle = 1
circle screen width()/2,screen height()/2,8
EndIf
k$=upper$(Inkey$())
`This code constitutes the movement functionality
If UpKey()=1 or k$="W"
`move the player forward
XRotate Object ColliderObjNum,0
Move Object ColliderObjNum,Delta#
XRotate Object ColliderObjNum,cx#
EndIf
If DownKey()=1 or k$="S"
`move the player backwards
XRotate Object ColliderObjNum,0
Move Object ColliderObjNum,0-Delta#
XRotate Object ColliderObjNum,cx#
EndIf
If LeftKey()=1 or k$="A"
`strafe left
XRotate Object ColliderObjNum,0
YRotate Object ColliderObjNum,cy#-90
Move Object ColliderObjNum,Delta#
YRotate Object ColliderObjNum,cy#
XRotate Object ColliderObjNum,cx#
EndIf
If RightKey()=1 or k$="D"
`strafe right
XRotate Object ColliderObjNum,0
YRotate Object ColliderObjNum,cy#-90
Move Object ColliderObjNum,0-Delta#
YRotate Object ColliderObjNum,cy#
XRotate Object ColliderObjNum,cx#
EndIf
If Shiftkey()=1
MovePerSec = 290
YRotate Object ColliderObjNum,cy#
XRotate Object ColliderObjNum,cx#
ENDIF
IF Shiftkey()=0
MovePerSec = 140
ENDIF
`screen particulars
Sync On : Sync Rate 0
Autocam Off : Hide Mouse
set display mode 1024,768,32
LOAD MUSIC "C:\Documents and Settings\XPPRO\My Documents\Downloads\Arcadia.mp3",1
PLAY MUSIC 1
Set Camera Range .1, 51000
`player's movement rate
`in quants per second,inches
`per second
Global MovePerSec As float
MovePerSec = 140
`reticle
Global UseReticle As Boolean
UseReticle = 1
`height
Global EyeHeight As Integer
EyeHeight = 100
`mouse's sensitivity
Global MouseSens As integer
MouseSens = 7
`falling
Global Airborn as Boolean
Global Gravity as Float
Gravity = 412
`map file
LoadMap:
Load Object "C:\Program Files\The Game Creators\Dark Basic Professional\castle\eow.dbo", 1
`collision to polygons
Set Object Collision To Polygons 1
`global variable
Global ColliderObjNum As Integer
ColliderObjNum = 2
`collider Object
Make Object Sphere ColliderObjNum, EyeHeight/2
`collision method
Set Object Collision On ColliderObjNum
Hide Object ColliderObjNum
`place the Camera
Position Camera 0, 3, 0,
`collider Object around the Camera
Position Object ColliderObjNum, 0, 0, 0
`ambient light level
Set Ambient Light 80
Fog Color RGB(192, 192, 192)
Fog Distance 3000
Fog On
`main loop
MainLoop:
Do
`sliding collision function
if Airborn=0 then CheckCollision()
if Airborn=1 then Fall()
`render
Sync
Loop
End
Function Fall()
`function for falling
`collider's current position
ox#=Object Position x(ColliderObjNum)
oy#=Object Position y(ColliderObjNum)
oz#=Object Position z(ColliderObjNum)
Delta#=Gravity/Screen FPS()
`Y value falling to
ny#=EyeHeight + (oy#-Intersect Object(1, ox#, oy#, oz#, ox#, -1000, oz#))
If (oy#-ny#)<=Delta#
`final position
Position Object ColliderObjNum, ox#, ny#, oz#
Position Camera 0, ox#, ny#, oz#
`Shut off AirBorn flag
Airborn = 0
Else
Position Object ColliderObjNum, ox#, oy#-delta#, oz#
Position Camera 0, ox#, oy#-delta#, oz#
EndIf
`draw the reticle during fall
If UseReticle = 1
circle screen width()/2,screen height()/2,8
EndIf
EndFunction
Function CheckCollision()
Moving = 0
`Begin Routine
`current Camera position
ox#=Object Position x(ColliderObjNum)
oy#=Object Position y(ColliderObjNum)
oz#=Object Position z(ColliderObjNum)
`how fast the machine is running
Delta#=MovePerSec/Screen FPS()
If Delta#>EyeHeight
Delta#=EyeHeight
EndIf
`accept user's input
Rotate Object ColliderObjNum, Object Angle x(ColliderObjNum)+(MouseMovey()/MouseSens),Object Angle y(ColliderObjNum)+(MouseMovex()/MouseSens),0
`this code constitutes the mouselook functionality
If Object Angle x(ColliderObjNum)>90 then XRotate Object ColliderObjNum,90
If Object Angle x(ColliderObjNum)<-90 then XRotate Object ColliderObjNum,-90
cx#=Object Angle x(ColliderObjNum)
cy#=Object Angle y(ColliderObjNum)
cz#=Object Angle z(ColliderObjNum)
Rotate Camera cx#, cy#, cz#
Rotate Object ColliderObjNum, cx#, cy#, cz#
If UseReticle = 1
circle screen width()/2,screen height()/2,8
EndIf
k$=upper$(Inkey$())
`This code constitutes the movement functionality
If UpKey()=1 or k$="W"
`move the player forward
XRotate Object ColliderObjNum,0
Move Object ColliderObjNum,Delta#
XRotate Object ColliderObjNum,cx#
EndIf
If DownKey()=1 or k$="S"
`move the player backwards
XRotate Object ColliderObjNum,0
Move Object ColliderObjNum,0-Delta#
XRotate Object ColliderObjNum,cx#
EndIf
If LeftKey()=1 or k$="A"
`strafe left
XRotate Object ColliderObjNum,0
YRotate Object ColliderObjNum,cy#-90
Move Object ColliderObjNum,Delta#
YRotate Object ColliderObjNum,cy#
XRotate Object ColliderObjNum,cx#
EndIf
If RightKey()=1 or k$="D"
`strafe right
XRotate Object ColliderObjNum,0
YRotate Object ColliderObjNum,cy#-90
Move Object ColliderObjNum,0-Delta#
YRotate Object ColliderObjNum,cy#
XRotate Object ColliderObjNum,cx#
EndIf
If Shiftkey()=1
MovePerSec = 290
YRotate Object ColliderObjNum,cy#
XRotate Object ColliderObjNum,cx#
ENDIF
IF Shiftkey()=0
MovePerSec = 140
ENDIF
`record the collider's new X/Z position
nx#=Object Position x(ColliderObjNum)
nz#=Object Position z(ColliderObjNum)
`floor height at the new position
ny#=EyeHeight + (oy#-Intersect Object(1, nx#, oy#, nz#, nx#, -1000, nz#))
if nx# > ox#
newxwest# = intersect object(1,nx#,ny#,nz#,nx#+(EyeHeight/2),ny#,nz#)
endif
if newxwest# > 0
if newxwest# < object size x(2)/2
nx# = ox#
endif
endif
`check to see if there's a collision
if object collision(ColliderObjNum,0) <> 0
position object ColliderObjNum, ox#, ny#, nz#
if object collision(ColliderObjNum, 0)<>0
Position object ColliderObjNum, nx#, ny#, oz#
If Object Collision(ColliderObjNum, 0)<>0
`Using the old Z value did not eliminate the collision
Position Object ColliderObjNum, nx#, oy#, nz#
If Object Collision(ColliderObjNum, 0)<>0
`just put the player back where they started from.
ny#=oy#
nx#=ox#
nz#=oz#
Else
`The new Y value, was the problem,
ny#=oy#
EndIf
Else
`The New Z value was the problem
nz#=oz#
EndIf
else
`The new X value was the culprit
nx# = ox#
endif
EndIf
if (oy#-ny#) > EyeHeight
AirBorn = 1
ny#=oy#
`damage is best calculated.
`safely allow the player to fall at this location.
CheckFall()
EndIF
`move the Camera and collider to the final adjudicated position
Position Camera 0, nx#, ny#, nz#
Position Object ColliderObjNum, nx#, ny#, nz#
EndFunction
Function CheckFall()
`check to see if the place you are going to fall to is going to
`create a collision.
ox#=Object Position x(ColliderObjNum)
oy#=Object Position y(ColliderObjNum)
oz#=Object Position z(ColliderObjNum)
`determine where the final resting location is after the fall is
`complete
ny#=EyeHeight + (oy#-Intersect Object(1, ox#, oy#, oz#, ox#, -1000, oz#))
`quickly position the collider there
position object ColliderObjNum, ox#, ny#, oz#
`see if there is a collision at the proposed location
if object collision(ColliderObjNum,0) <> 0
Airborn=0
EndIf
EndFunction