Sliding Collision 2 |
Move about and detect collisions without building collision boxes. |
` Author: Hop A Long ` December 12, 2004 ` A 'chain' of collision checks allows the player to navigate an internal corner. `*****SET UP***** autocam off sync rate 30 sync on hide mouse `*****BEGIN LOADING THE MODELS***** Make Object Box 8,10,3,1 Position Object 8,0,-3,15 Color Object 8, RGB(255,128,128) Make Object Box 9,1,3,10 Position Object 9,-5,-3,10 Color Object 9, RGB(190,243,139) Make Object Box 10,1,3,10 Position Object 10,5,-3,10 Color Object 10, RGB(247,128,238) ` Make the Player / Camera Make Object Box 7,7,5,7 Position Object 7,0,10,0 Position Camera 0,10,0 `*****BEGIN THE LOOP***** Do `******************************** ` Use the Mouse to turn `******************************** ` Use MOUSEMOVE to alter camera angles ` The view follows no object in particular and is free to roam. ang_x#=wrapvalue(ang_x#+mousemovey()*0.2) ang_y#=wrapvalue(ang_y#+mousemovex()*0.2) Rotate camera ang_x#,ang_y#,0 `*****STORE PLAYER POSITION***** x_saved# = Object Position X(7) y_saved# = Object Position Y(7) z_saved# = Object Position Z(7) `******************************** ` Simple movement `******************************** If Upkey() =1 then move camera 1 If Downkey()=1 then move camera -1 ` Get the Camera values x# = camera position x() z# = camera position z() y# = 0.0 `Slide Left If LeftKey()=1 x# = NewXValue(x#,WrapValue(ang_y#-90),1) z# = NewZValue(z#,WrapValue(ang_y#-90),1) EndIf `Slide Right If RightKey()=1 x# = NewXValue(x#,WrapValue(ang_y#+90),1) z# = NewZValue(z#,WrapValue(ang_y#+90),1) 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***** obj_id = 0 new_obj_id = 0 If Object Collision(7,0)>0 ` A collision was detected. obj_id = Object Collision(7,0) ` Reposition the player's box with the adjusted values. If Object Collision(7,obj_id)>0 Then Position Object 7, x_saved#,player_y#,player_z# If Object Collision(7,obj_id)>0 Then Position Object 7, player_x#,y_saved#,player_z# If Object Collision(7,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 new_obj_id = Object Collision(7,0) If new_obj_id <> obj_id ` Reposition the player's box with the adjusted values. If Object Collision(7,new_obj_id)>0 Then Position Object 7, x_saved#,player_y#,player_z# If Object Collision(7,new_obj_id)>0 Then Position Object 7, player_x#,y_saved#,player_z# If Object Collision(7,new_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 Position camera x#,y#,z# `*****FORMAT OUTPUT************************************* Center Text 320,20, "FIRST PERSON CAMERA WALK" Center Text 320,40, "Mouse:Turn/Look Up Arrow:Forward Down Arrow:Back L/R Arrow:Sideways" Text 10,400,"camera x value: "+str$(x#) Text 10,420,"camera y value: "+str$(y#) Text 10,440,"camera z value: "+str$(z#) If obj_id <> 0 obj1_x# = Object Position X(obj_id) obj1_y# = Object Position Y(obj_id) obj1_z# = Object Position Z(obj_id) Text 200,380,"col 1 : "+str$(obj_id) Text 200,400,"obj1 x : "+str$(obj1_x#) Text 200,420,"obj1 y : "+str$(obj1_y#) Text 200,440,"obj1 z : "+str$(obj1_z#) EndIf If new_obj_id <> 0 obj2_x# = Object Position X(new_obj_id) obj2_y# = Object Position Y(new_obj_id) obj2_z# = Object Position Z(new_obj_id) Text 300,380,"col 2 : "+str$(new_obj_id) Text 300,400,"obj2 x : "+str$(obj2_x#) Text 300,420,"obj2 y : "+str$(obj2_y#) Text 300,440,"obj2 z : "+str$(obj2_z#) EndIf `*****UPDATE THE SCREEN***** Sync Loop `*****END OF MAIN LOOP************* |