| Generate sliding collision in a complicated model by hiding collision boxes inside. The media for use with the code can be downloaded here. |
| `Title: Shuttle Dock `Date: July 17, 2005 `Author: Hop A Long `*****SET UP***** autocam off sync rate 30 sync on hide mouse Backdrop On Color Backdrop RGB(0,0,0) `*****Program Variables***** speed# = 0.2 show$ = "YES" `*****Load the World***** Load Object "shuttle.x", 1 ` Load the shuttle's collision boxes. For obj = 1 To 8 Load Object "box"+str$(obj)+".x", obj+10 Hide Object obj+10 Next obj `*****Make the Player***** Make Object Box 7,5,5,5 Position Object 7,0,0,-30 Hide Object 7 `*****Set Up Camera***** Position Camera 0,0,-30 `*****BEGIN THE LOOP***** Do `*****STORE PLAYER POSITION***** x_saved# = Object Position X(7) y_saved# = Object Position Y(7) z_saved# = Object Position Z(7) `******************************** ` Use the Mouse to turn `******************************** ` Use MOUSEMOVE to alter camera angles ang_x#=wrapvalue(ang_x#+mousemovey()*0.05) ang_y#=wrapvalue(ang_y#+mousemovex()*0.05) Rotate camera ang_x#,ang_y#,0 `******************************** ` Simple movement `******************************** If Upkey() =1 then move camera speed# If Downkey()=1 then move camera (speed# * -1) ` Get the Camera values x# = camera position x() y# = camera position y() z# = camera position z() `Slide Left If LeftKey()=1 x# = NewXValue(x#,WrapValue(ang_y#-90),speed#) z# = NewZValue(z#,WrapValue(ang_y#-90),speed#) EndIf `Slide Right If RightKey()=1 x# = NewXValue(x#,WrapValue(ang_y#+90),speed#) z# = NewZValue(z#,WrapValue(ang_y#+90),speed#) EndIf ` Assign the camera values to the Player's Collision Box player_x# = x# player_y# = y# player_z# = z# ` Position the Player's Collision Box at the Camera location Position Object 7, player_x#, player_y#, player_z# `*****CHECK THE PLAYER'S BOX FOR COLLISION***** first_obj_id = 0 second_obj_id = 0 third_obj_id = 0 If Object Collision(7,0)>10 ` A collision was detected. first_obj_id = Object Collision(7,0) ` Reposition the player's box with the adjusted values. If Object Collision(7,first_obj_id)>0 Then Position Object 7, x_saved#,player_y#,player_z# If Object Collision(7,first_obj_id)>0 Then Position Object 7, player_x#,y_saved#,player_z# If Object Collision(7,first_obj_id)>0 Then Position Object 7, player_x#,player_y#,z_saved# player_x# = Object Position X(7) player_y# = Object Position Y(7) player_z# = Object Position Z(7) x# = player_x# y# = player_y# z# = player_z# EndIf ` Check if a second collision occurred while checking the first second_obj_id = Object Collision(7,0) If second_obj_id <> first_obj_id And second_obj_id > 10 ` Reposition the player's box with the adjusted values. If Object Collision(7,second_obj_id)>0 Then Position Object 7, x_saved#,player_y#,player_z# If Object Collision(7,second_obj_id)>0 Then Position Object 7, player_x#,y_saved#,player_z# If Object Collision(7,second_obj_id)>0 Then Position Object 7, player_x#,player_y#,z_saved# player_x# = Object Position X(7) player_y# = Object Position Y(7) player_z# = Object Position Z(7) x# = player_x# y# = player_y# z# = player_z# EndIf third_obj_id = Object Collision(7,0) If third_obj_id > 10 If third_obj_id <> second_obj_id And third_obj_id <> first_first_obj_id ` Reposition the player's box with the adjusted values. If Object Collision(7,third_obj_id)>0 Then Position Object 7, x_saved#,player_y#,player_z# If Object Collision(7,third_obj_id)>0 Then Position Object 7, player_x#,y_saved#,player_z# If Object Collision(7,third_obj_id)>0 Then Position Object 7, player_x#,player_y#,z_saved# player_x# = Object Position X(7) player_y# = Object Position Y(7) player_z# = Object Position Z(7) x# = player_x# y# = player_y# z# = player_z# EndIf EndIf Position camera x#,y#,z# `*****FORMAT OUTPUT************************************* Center Text 320,20, "SHUTTLE DOCK" Center Text 320,40, "Mouse:Turn/Look Up Arrow:Forward Down Arrow:Back L/R Arrow:Sideways" key = Scancode() `s If key = 31 Then show$ = "YES" `h If key = 35 Then show$ = "NO" If show$ = "YES" Text 10,400,"camera x value: "+str$(x#) Text 10,420,"camera y value: "+str$(y#) Text 10,440,"camera z value: "+str$(z#) Text 10,460,"player y value: "+str$(player_y#) If first_obj_id <> 0 Text 190,380,"col 1 : "+str$(first_obj_id) EndIf If second_obj_id <> 0 Text 190,400,"col 2 : "+str$(second_obj_id) EndIf If third_obj_id <> 0 Text 190,420,"col 3 : "+str$(third_obj_id) EndIf frames = Screen fps() Text 190,460,"FPS : "+str$(frames) EndIf `*****UPDATE THE SCREEN***** Sync Loop `*****END OF MAIN LOOP************* |
![]() |
| SHUTTLE DOCK |