Page 1 of 4 123 ... LastLast
Results 1 to 10 of 40

Thread: How to put togeather a good sprint mechanic.

  1. #1
    meganaut
    Guest

    Lightbulb 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. #2
    Kauppaneuvos
    Guest
    Looks nice, probably going to use this in sprinting-state.

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

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

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

    haha

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

  7. #7
    meganaut
    Guest
    Quote 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

  8. #8
    meganaut
    Guest
    Added a video

  9. #9
    Derp
    Guest
    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?

  10. #10
    Whaaabamb
    Guest
    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
    
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •