Announcement

Collapse

The Infinity Blade Forums Have Moved

We've launched brand new Infinity Blade forums with improved features and revamped layout. We've also included a complete archive of the previous posts. Come check out the new Infinity Blade forums.
See more
See less

How to put togeather a good sprint mechanic.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to put togeather a good sprint mechanic.

    Howdy people,

    I spent a little bit of time today putting togeather a tutorial on building a sprint mechanic. This is my first tutorial and as such its pretty rough. So I would appreciate any feedback etc..

    here is the link

    It goes through the process of setting up a sprint system with the following features:
    • A stamina system that allows the player to become puffed out and need to stop to catch his breath.
    • A basic HUD to show your stamina bar (as well as health).
    • Motionblur that blends on while sprinting then off again afterwards.
    • An interpolated thirdperson camera translation for moving into a different position for sprinting.
    • A system for interpolating the FOV of the player camera while sprinting.
    • Strafing and walking backwards are disabled while sprinting.
    • The speed that you can look around is reduced while sprinting.

    I would prefer if you left comments here, rather than on the blog.

    -Mega

    -Edit: heres a video of the system in action

  • #2
    Looks nice, probably going to use this in sprinting-state.

    Comment


    • #3
      Thank your for this, I like the extra features such as the HUD and disabling walking backwards. Nice Job!

      Comment


      • #4
        Nice tutorial. Have to say though, your website is very narrow!

        Comment


        • #5
          Originally posted by Zaiteria View Post
          Nice tutorial. Have to say though, your website is very narrow!
          How dare you!!

          haha

          Comment


          • #6
            A YouTube of it in action would be nice to have, so you know what you get from this

            Comment


            • #7
              Originally posted by vipar View Post
              A YouTube of it in action would be nice to have, so you know what you get from this
              A good idea. Ill put one togeather and update this post and the tutorial

              Comment


              • #8
                Added a video

                Comment


                • #9
                  Great tutorial, have been trying to figure out how to stop sprinting backwards!

                  Also, out of curiosity, do you extend from the UT classes or UDK?

                  Comment


                  • #10
                    Wow awesome this looks great!

                    Plugging it in just getting the sprint and stamina functions in. no HUD or FX yet. When I plugged it in, I lost control over my character and camera. For a bit i had it working in myPawn.uc but then realized you said to put it in player controller... when it was in pawn it worked except for i never ran out of stamina :/

                    Thanks again for the tut though! did i miss something?

                    *myPlayerController.uc
                    Code:
                    class RunPlayerController extends PlayerController
                        config(RunGame);
                    
                    // members for the custom mesh
                    var SkeletalMesh defaultMesh;
                    var MaterialInterface defaultMaterial0;
                    var MaterialInterface defaultMaterial1;
                    var AnimTree defaultAnimTree;
                    var array <animset> defaultAnimSet;
                    var AnimNodeSequence defaultAnimSeq;
                    var PhysicsAsset defaultPhysicsAsset;
                    //Sprint handling variables
                    var float SprintSpeed;
                    var float WalkSpeed;
                    var float Stamina;
                    
                    var bool bSprinting;
                    var bool bPuffedOut;
                    
                    //Update player rotation when walking
                    state PlayerWalking
                    {
                    ignores SeePlayer, HearNoise, Bump;
                    
                    
                      function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
                        {
                            local Rotator CameraRotationYawOnly;
                            if( Pawn == None )
                            {
                                return;
                            }
                    
                            if (Role == ROLE_Authority)
                            {
                                // Update ViewPitch for remote clients
                                Pawn.SetRemoteViewPitch( Rotation.Pitch );
                            }
                    
                            Pawn.Acceleration = NewAccel;
                    
                                 //get the controller yaw to transform our movement-accelerations by
                        CameraRotationYawOnly.Yaw = Rotation.Yaw; 
                        NewAccel = NewAccel>>CameraRotationYawOnly; //transform the input by the camera World orientation so that it's in World frame
                        Pawn.Acceleration = NewAccel;
                       
                        Pawn.FaceRotation(Rotation,DeltaTime); //notify pawn of rotation
                    
                            CheckJumpOrDuck();
                        }
                    
                        function PlayerMove( float DeltaTime )
                        {
                            local vector            X,Y,Z, NewAccel;
                            local eDoubleClickDir    DoubleClickMove;
                            local rotator            OldRotation;
                            local bool                bSaveJump;
                    
                            if( Pawn == None )
                            {
                                GotoState('Dead');
                            }
                            else
                            {
                                GetAxes(Pawn.Rotation,X,Y,Z);
                    
                                // Update acceleration.
                                NewAccel.X = PlayerInput.aForward;
                                NewAccel.Y = PlayerInput.aStrafe;
                                NewAccel.Z    = 0;
                                //NewAccel = Pawn.AccelRate * Normal(NewAccel);
                    
                                if (IsLocalPlayerController())
                                {
                                    AdjustPlayerWalkingMoveAccel(NewAccel);
                                }
                    
                                DoubleClickMove = PlayerInput.CheckForDoubleClickMove( DeltaTime/WorldInfo.TimeDilation );
                    
                                // Update rotation.
                                OldRotation = Rotation;
                                UpdateRotation( DeltaTime );
                                bDoubleJump = false;
                    
                                if( bPressedJump && Pawn.CannotJumpNow() )
                                {
                                    bSaveJump = true;
                                    bPressedJump = false;
                                }
                                else
                                {
                                    bSaveJump = false;
                                }
                    
                                if( Role < ROLE_Authority ) // then save this move and replicate it
                                {
                                    ReplicateMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
                                }
                                else
                                {
                                    ProcessMove(DeltaTime, NewAccel, DoubleClickMove, OldRotation - Rotation);
                                }
                                bPressedJump = bSaveJump;
                            }
                        }
                    
                        event BeginState(Name PreviousStateName)
                        {
                            DoubleClickDir = DCLICK_None;
                            bPressedJump = false;
                            GroundPitch = 0;
                            if ( Pawn != None )
                            {
                                Pawn.ShouldCrouch(false);
                                if (Pawn.Physics != PHYS_Falling && Pawn.Physics != PHYS_RigidBody) // FIXME HACK!!!
                                    Pawn.SetPhysics(Pawn.WalkingPhysics);
                            }
                        }
                    
                        event EndState(Name NextStateName)
                        {
                            GroundPitch = 0;
                            if ( Pawn != None )
                            {
                                Pawn.SetRemoteViewPitch( 0 );
                                if ( bDuck == 0 )
                                {
                                    Pawn.ShouldCrouch(false);
                                }
                            }
                        }
                    
                    Begin:
                    }
                    
                    //Controller rotates with turning input
                    function UpdateRotation( float DeltaTime )
                    {
                    local Rotator   DeltaRot, newRotation, ViewRotation;
                    
                       ViewRotation = Rotation;
                       if (Pawn!=none)
                       {
                          Pawn.SetDesiredRotation(ViewRotation);
                       }
                    
                       // Calculate Delta to be applied on ViewRotation
                       DeltaRot.Yaw   = PlayerInput.aTurn;
                       DeltaRot.Pitch   = PlayerInput.aLookUp;
                    
                       ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
                       SetRotation(ViewRotation);
                    
                       NewRotation = ViewRotation;
                       NewRotation.Roll = Rotation.Roll;
                    
                       if ( Pawn != None )
                          Pawn.FaceRotation(NewRotation, deltatime); //notify pawn of rotation
                    }   
                    
                    
                    
                    
                    function startSprint()
                    {
                    ConsoleCommand("Sprint");
                    
                      if( !bPuffedOut )
                      {
                        Pawn.GroundSpeed = SprintSpeed;
                     
                        bSprinting = true;
                      }
                    }
                     
                    function stopSprint()
                    {
                      Pawn.GroundSpeed = WalkSpeed;
                      bSprinting = false;
                    
                      //bPuffedOut = false; --only use this if you dont have a puffed timer func or a puffed state.
                    }
                    
                    simulated function PlayerTick( float DeltaTime )
                    {
                     
                       //sprinting use and replenish code.
                      if( bSprinting && !bPuffedOut )
                      {
                        Stamina -= 20.4 * DeltaTime;
                      }
                      else
                      {
                        if( Stamina < 100 && !bPuffedOut )
                        {
                          Stamina += 0.2 * DeltaTime;
                        }
                      }
                     
                       //cases for low stamina
                      if( Stamina <= 0 && !bPuffedOut )
                      {
                        //go into puffed state -- you could set up the state to play different idle and walking animations where the player looks workn out.
                        //Also you could make the player stand still for a certain amount of time while they catch their breath.
                        // i.e.  GoToState( 'Puffed', 'CatchBreath' );
                        Stamina = 0;
                        bPuffedOut = true;
                       Pawn.GroundSpeed = 50;
                        SetTimer( 3.f, false, 'CaughtBreath' );
                      }
                      else
                      {
                        if( !bSprinting && !bPuffedOut )
                        {
                          Pawn.GroundSpeed = WalkSpeed;
                        }
                      }
                    
                    }
                     
                    function CaughtBreath()
                    {
                      bPuffedOut = false;
                    }
                    
                    
                    // Sets the Pawns Mesh to the resources speced in the DefaultProperties
                    public function resetMesh(){
                    self.Pawn.Mesh.SetSkeletalMesh(defaultMesh);
                    self.Pawn.Mesh.SetMaterial(0,defaultMaterial0);
                    self.Pawn.Mesh.SetMaterial(1,defaultMaterial1);
                    self.Pawn.Mesh.SetPhysicsAsset(defaultPhysicsAsset );
                    self.Pawn.Mesh.AnimSets=defaultAnimSet;
                    self.Pawn.Mesh.SetAnimTreeTemplate(defaultAnimTree );
                    }
                    
                    
                    DefaultProperties
                    {
                    
                    
                    InputClass=class'Run.RunPlayerInput'
                    CameraClass=class'Run.RunPlayerCamera'
                    defaultMesh=SkeletalMesh'Run_Core.Character.Run_Girl_skel'
                    defaultAnimTree=AnimTree'Run_Core.Character.Character_movement'
                    defaultAnimSet(0)=AnimSet'Run_Core.Character.Run_Girl_skel_Anims'
                    defaultPhysicsAsset=PhysicsAsset'Run_Core.Character.Run_Girl_skel_Physics'
                    //UTHUDBase(myHUD).bCrosshairShow = false
                    
                    
                        WalkSpeed=350.0
                        SprintSpeed=900.0
                        bSprinting=false
                        bPuffedOut = false
                        Stamina=100.0
                    
                    }

                    Comment


                    • #11
                      Has anyone had any luck getting getting this set up with classes extending from UDKBase?

                      Comment


                      • #12
                        Originally posted by Derp View Post
                        Great tutorial, have been trying to figure out how to stop sprinting backwards!

                        Also, out of curiosity, do you extend from the UT classes or UDK?
                        All my classes are extended from UDK. no UT code (except that which i stole from UT classes) is used

                        Comment


                        • #13
                          Originally posted by Whaaabamb View Post
                          Wow awesome this looks great!

                          Plugging it in just getting the sprint and stamina functions in. no HUD or FX yet. When I plugged it in, I lost control over my character and camera. For a bit i had it working in myPawn.uc but then realized you said to put it in player controller... when it was in pawn it worked except for i never ran out of stamina :/
                          I'm not certain... It may be because i extended my custom controllre class from UDKPlayerController. give that a try and let me know.

                          -Mega

                          Comment


                          • #14
                            I wanted to do a little extra with your sprinting, and I just can't really make it work.
                            I haven't implemented much of the system yet, but usually I like to compile from time to time, so that I know what I've done so far works...habit from making Java :P

                            So any way.
                            What I am trying to do, is make the HUD show a message in the middle of the screen, if the player tries to sprint, but can't, as I don't want the Sprint Meter you show in the video ^^
                            So I thought "Why not do it like Java since this is Java/C++ inspired?" So I tried to make the function static, and then did HS_GameHUD.DisplayExhausted(...); in my player controller but apparently that is not how to do it...some help would be nice

                            This is from my Player Controller, which extends UTPlayerController:
                            Code:
                            function startSprint() {
                            	if(!bExhausted) {
                            		Pawn.GroundSpeed = SprintSpeed;
                            		bSprinting = true;
                            	} else {
                            		HS_GameHUD.DisplayExhausted("You are too Exhausted to Sprint.");
                            	}
                            }
                            And this is from my HUD class which extends UTHud:

                            Code:
                            function DisplayExhausted(string s) {
                            	Canvas.SetPos((Canvas.ClipX / 2), (Canvas.ClipY /2));
                            	Canvas.DrawText(s, true, 2.0f, 2.0f);
                            }

                            Comment


                            • #15
                              Well you dont need the function to be static since you only use one HUD. The static keyword should be used to make a variable (or function i guess) exist in one instance accross all seperate instances of that class. I'm pretty sure thats how it works in java too, so I'm not really understanding your reasoning behind making the function static.

                              The other thing is you should set a draw colour for your text:
                              Code:
                               Canvas.DrawColor = WhiteColor;
                              That should work if you are using a version of my HUD

                              -Mega

                              Comment

                              Working...
                              X