MORE CODE | |||||||||||||
Skinny's Walk | |||||||||||||
Load an Animated Model. Control it's movement with Key Board input. Set up for Sliding Collision. |
|||||||||||||
To run the demo download the model files: idle skinny and walk skinny Unzip them into the folder that contains the demo source code. |
|||||||||||||
` Animated Model Collision ` September 20, 2004 ` Author: Hop A Long ` This demo requires two animation files that can be down loaded ` from the site. ` ****SET UP***** Sync On Sync Rate 30 Hide Mouse AutoCam Off Backdrop on Set camera range 1,500 Fog on Fog distance 400 Fog color RGB(180,128,128) Color Backdrop RGB(180,128,188) ` *****BUILD THE MATRIX Make matrix 1,1000,1000,15,15 Create Bitmap 1,256,256 : cls rgb(200,200,0) : ink rgb(0,150,0),0 For j = 1 to 4 Circle 128,128,j*32 Next j Get Image 1,0,0,256,256 : Delete Bitmap 1 Prepare Matrix Texture 1,1,1,1 Fill Matrix 1,0,1 ` *****LOAD MR. SKINNY***** ` Load Skinny Files idlestart=0 Load Object "idle skinny.x",2 : idleend=Total Object Frames(2) walkstart=Total object Frames(2)+1 Append Object "walk skinny.x",2,walkstart : walkend=Total Object Frames(2) Scale Object 2,1200,1200,1200 Fix Object Pivot 2 Yrotate object 2,225 Position Object 2,500,Get Ground Height(1,500,500),500 ` Get dimensions for the collision box. This is not accurate. ` The model has been scaled. Add space for the feet when walking. x# = Object Size X(2)+15.0 y# = Object Size Y(2) z# = Object Size Z(2)+15.0 Make Object Collision Box 2, -1*x#, -1*y#, -1*z#, x#, y#, z#,0 ` *****MAKE SOME OBJECTS***** Make Object Box 3,100,40,4 Position Object 3,500,20,540 Color Object 3,RGB(140,240,33) Make Object Collision Box 3,-50,-20,-2,50,20,2,0 Make Object Box 4,4,40,80 Position Object 4,400,20,500 Color Object 4,RGB(140,240,33) Make Object Collision Box 4,-2,-20,-40,2,20,40,0 Make Object Box 5,4,40,80 Position Object 5,600,20,500 Color Object 5,RGB(140,240,33) Make Object Collision Box 5,-2,-20,-40,2,20,40,0 ` *****ASSIGN START VALUES***** action$ = "IDLE" last_action$ = "IDLE" ` *****************************MAIN LOOP*********************************** Do frame = Object Frame(2) `********************************* ` MR. SKINNY ANIMATION ROUTINES `********************************* ` Idle Key If ControlKey() = 1 If last_action$ = "WALK" Then action$ = "PREP IDLE" EndIf ` Walk Key If ShiftKey() = 1 If last_action$ = "IDLE" Then action$ = "PREP WALK" EndIf ` Idle Routine If action$ = "IDLE" Set Object Speed 2,30 Loop Object 2,idlestart,idleend EndIf ` Change from Idle to Walk Routine If action$ = "PREP WALK" If frame = idlestart Set Object Frame 2,walkstart last_action$ = "WALK" action$ = "WALK" EndIf EndIf ` Play walking animation If action$ = "WALK" Set Object Speed 2,40 Loop Object 2,walkstart,walkend ` Move Mr. Skinny Move Object 2,1.0 ` EndIf EndIf ` Change from Walk to Idle Routine If action$ = "PREP IDLE" ` The two frames when the walk is closest to standing. If frame = 62 Or frame = 92 Set Object Frame 2,idlestart last_action$ = "IDLE" action$ = "IDLE" EndIf Move Object 2,0.8 EndIf ` ********************************** ` Turn MR.SKINNY With Keys ` ********************************** ` Store SKINNY'S Y angle in skinny_y_ang# skinny_y_ang# = Object Angle Y(2) ` Turn MR.SKINNY Left or Right When Walking If Leftkey()=1 Then skinny_y_ang# = Wrapvalue(skinny_y_ang#-3) If Rightkey()=1 Then skinny_y_ang# = Wrapvalue(skinny_y_ang#+3) ` Rotate MR.SKINNY YRotate Object 2,skinny_y_ang# ` Get the Correct Matrix Height skinny_x# = Object Position X(2) skinny_z# = Object Position Z(2) skinny_y# = get ground height(1,skinny_x#,skinny_z#) Position Object 2,skinny_x#,skinny_y#,skinny_z# ` ******************************************* ` COLLISION ` ******************************************* obj_id = 0 ` Detect collision with an Object and Slide If Object Collision(2,0)>0 ` Obtain the object id for our text print out obj_id = Object Collision(2,0) Dec skinny_x#,get object collision x() Dec skinny_y#,get object collision y() Dec skinny_z#,get object collision z() Endif Position Object 2,skinny_x#,skinny_y#,skinny_z# ` ******************************************* ` SET CAMERA TO FOLLOW ` ******************************************* Set Camera To Follow skinny_x#,skinny_y#,skinny_z#,0,150,60,1,1 ` *****DISPLAY****** Ink RGB(250,250,250),0 Center Text 320,30,"SKINNY'S WALK" Center Text 320,50,"Shift: Walk Ctrl: Idle Left/Right Arrow: Turn" Text 10,380,"Animation : "+action$ Text 10,400,"frame: "+str$(frame) ` Easier to read without the decimal skinny_y = Int(skinny_y#) Text 10,420,"height : "+str$(skinny_y) Text 10,440,"collision with object: "+str$(obj_id) Text 10,460,"size x : "+str$(x#)+" size y : " +str$(y#)+" size z : "+str$(z#) ` *****REFRESH***** Sync Loop ` *************END OF LOOP************************************************ |