Blitz3D Animation and Control Part 2


Tweet blitz3d controller tutorials
(Posted 5 months ago) RonTek

Basic controls with walking and idle state

Updated: Turn controls and basic collisions added.

Author: GuyFawkes / Rontek

Blitz3D Animation and Control Part 2

Graphics3D 800, 600, 0, 2

Const PLAYER = 1, NPC = 2

Collisions PLAYER,NPC,2,3
Collisions NPC,PLAYER,2,3

AmbientLight 128,128,128
light=CreateLight(0)
Local camera = CreateCamera ( )
CameraClsColor camera,0,128,255
PositionEntity camera, 0, 5, 0
Local ninja = LoadAnimMesh ( "ninja.b3d" )
EntityType ninja,PLAYER
ScaleEntity ninja, .5, .5, .5
PositionEntity ninja, 0, 0, 10
PointEntity ( camera, ninja )
EntityParent ( camera, ninja )
MoveEntity ( camera, 0, 3, 0 )
Local i
For i=0 To 20
    Local cube = CreateCube ( )
    PositionEntity ( cube, -3, 0, i * 10 )
    EntityColor cube,Rand(255),Rand(255),Rand(255)
    EntityType cube,NPC
Next
Local anim_idle = ExtractAnimSeq ( ninja, 206, 250 ) ;Idle 2
Local anim_walk = ExtractAnimSeq ( ninja, 1, 14 ) ;anim sequence | 1: Walk (normal)
Local anim = 0
While Not KeyHit ( 1 )

    ; Turn Left or Right standing or while walking
    If KeyDown ( 32 ) Or KeyDown ( 205 )
    TurnEntity ( ninja,0,-.01,0)    
    ElseIf KeyDown ( 30 ) Or KeyDown ( 203 )
    TurnEntity ( ninja,0,.01,0) 
    EndIf

    ; Walk forward and back
    If KeyDown ( 31 ) Or KeyDown ( 208 )
        MoveEntity ( ninja, 0, 0, -0.005 )
        If anim <> anim_walk
            anim = anim_walk
            Animate ( ninja, 1, 0.003, anim, 0.001 )
        EndIf
    ElseIf KeyDown ( 17 ) Or KeyDown ( 200 )
        MoveEntity ( ninja, 0, 0, 0.005 )
        If anim <> anim_walk
            anim = anim_walk
            Animate ( ninja, 1, 0.003, anim, 0.001 )
        EndIf

    ElseIf anim <> anim_idle
        anim = anim_idle
        Animate ( ninja, 1, 0.001, anim, 0.001 )
    EndIf

    UpdateWorld ( )
    RenderWorld ( )
    Flip 0
Wend

End

Reply To Topic (minimum 10 characters)

Please log in to reply