Announcement

Collapse
No announcement yet.

Blueprints: Basic Sprint - Beginner Friendly

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

    [TUTORIAL] Blueprints: Basic Sprint - Beginner Friendly

    Hi there!

    Below is a beginner friendly (i hope) tutorial i have put together on how to implement a very basic sprinting system into your project.
    The tutorial is broken down into sections which should allow for easy following and brief explanations are provided for those who may be new to the Unreal Editor.

    I am aware that there are various tutorials/blueprint examples on the UE4 wiki, UE forums and Youtube which explains how to implement this much faster, however after this tutorial i shall also be submitting my stamina decay/regen tutorial which will build on the information provided in this tutorial.

    I hope the tutorial helps those who are new to the editor, if you get confused at any point or something is not working as intended then let me know.

    Additionally i have included an image at the end of the tutorial to act as a sort of TLDR, which provides a snapshot of the Blueprint setup if you wish to skip reading the less fun parts .

    If you think the tutorial is long winded or would be better presented an alternative way, please do let me know.

    Hope this helps somebody!

    ------

    1.0 - Project Creation
    1.1 - The first thing we want to do when we open Unreal Editor 4 is create a new project using the Third Person Game example with starter content. I have named my project ‘Sprint Tutorial’, however for sake of implementation your project does not necessarily need to have the same name.

    2.0 - Input Actions
    2.1 - The first thing we must do once our project has been created is set up our new input actions that are going to allow our character to sprint. To do this we must go into the project settings, which can be accessed along the top of the editor screen.


    2.2 - Within the Input section of our project settings, we are going to create a new action mapping bound to the Left Shift key. This action map will be named Sprint.


    3.0 - Sprint Blueprint
    3.1 - Now that we have our action mapping set, we must now create two variables within our ThirdPersonCharacter blueprint which will set the walk speed and run speed of our character.

    3.1.1 - With the ThirdPersonCharacter event graph open, nagivate to the variables of the blueprint which are typically on the left side of the editor. Click the + to create two new variable called Walk Speed and Run Speed. These variables will as standard be Boolean variables (true or false), however for our purposes we must ensure that they are Float variables (decimal numbers). To change our variables from Boolean to Float we can click on them and change their Variable Type to Float in the details panel at the right side of the editor.


    Now we have our variables created, we must now set their default values, to allow us to do that we must first compile our blueprint. With that done, if we click on either of the variables we can set their default values in the details pane (typically on the right side of the editor). In this instance, I have set my walk speed to 175.00 and run speed to 600.00.


    3.2 - With our variables now created and set, we must now work in the ThirdPersonCharacter blueprint to create our sprinting action.

    3.2.1 - The first thing we must do right click and create our InputAction Sprint node. We can do this by right clicking anywhere in our event graph and typing ‘Input Action Sprint’.

    3.2.2 - Now we must get a reference to our character movement as this allows us to manipulate the default movement values of our character. To get this reference, either drag and drop it from the components section of the editor (typically top left of the screen) or right click in the event graph and type ‘get character movement’ and add the Get Character Movemenent node.


    3.2.2 Now that we have reference to the character movement, we can now manipulate the max walk speed of our character. We can do this by adding a Set Max Walk Speed node to our event graph, this is done by dragging a wire from our character movement reference and adding the Set Max Walk Speed node.


    3.2.3 - We must now join our InputAction Sprint Pressed pin to our Set Max walk Speed node pin. Also we must set the value of our Max Walk Speed pin when our InputAction Sprint is pressed, we do this by referencing the ‘Run Speed’ variable we created in part 3.1.1. This can be done either by dragging and dropping the node from our variable sections on the left side of the editor or by right clicking and typing ‘get run speed’ and adding the Run Speed node. Now drag a wire from the Run Speed node and connect it to the Max Walk Speed pin of our Set Max Walk Speed node.


    3.2.4 - Now if we compiled and tested our project, our characters max walk speed changes from 175.00 to 600.00 when our InputAction Sprint is pressed, but nothing happens when we release our InputAction. The desired effect is for our character to return back to a walking speed when released and to do this we insert a very similar set of nodes that we used for the InputAction Sprint Pressed pin. We can copy the Set Max Walk Speed node and link this to the InputAction Sprint Released pin. Then we must set a value for the max walk speed when released just like in 3.2.3. We will do this by creating a reference to our Walk Speed variable we created earlier and linking this to our Max Walk Speed pin. Multiple wires can be taken from the character movement reference, so again link this to our target of the Set Max Walk Speed Node.


    3.2.5 - The last thing we must add within our blueprint is an Event BeginPlay node which we will use to set the Max Walk Speed of our character when our game is first started. These nodes will be set up similar to the previous set of nodes, where we are setting the Max Walk Speed by referencing our Walk Speed variable.


    4.0 - Compile and Test
    4.1 - Now we can compile our blueprint and test our project to ensure our sprint is working as intended. When in play, we can press and hold the shift key to increase our characters movement speed and when released our character returns back to a walking speed.

    TLDR
    Set up your Event Graph as per the below image and ensure your variables have been set as per section 3.0.

    Twitter: ItsConnorReid

    Blueprint Tutorial | Basic Sprint - Beginner Friendly | Forum | Wiki
    Blueprint Tutorial | Stamina Decay/Regeneration Implementation | Forum
    Blueprint Tutorial | Stamina/Progress Bar Implementation | Forum

    #2
    Thank you, it works great and it's pretty well documented.

    Comment


      #3
      I know this is a few months old, but it was really helpful good job, man. I used it not only to add sprint to my FPS/TPS, but also to add a slower Aim Down Sights speed. Very useful, thanks for writing it up.

      Comment


        #4
        Hi At0micCyb0rg,

        Thanks for the kind words, glad it helped you out mate.

        Connor.
        Twitter: ItsConnorReid

        Blueprint Tutorial | Basic Sprint - Beginner Friendly | Forum | Wiki
        Blueprint Tutorial | Stamina Decay/Regeneration Implementation | Forum
        Blueprint Tutorial | Stamina/Progress Bar Implementation | Forum

        Comment


          #5
          Hey, since you put so much effort into this tutorial, why don't you start posting in the community wiki instead?
          Github - YouTube - Unreal Slackers - KITATUS

          Comment


            #6
            Hi Zarkopafilis,

            I had originally intended to stick it up on the Wiki, however could not quite get to grips with creating a new page.

            I shall give it another go tonight or tomorrow and hopefully with some success I will also get the other tutorials up there.

            Connor.
            Twitter: ItsConnorReid

            Blueprint Tutorial | Basic Sprint - Beginner Friendly | Forum | Wiki
            Blueprint Tutorial | Stamina Decay/Regeneration Implementation | Forum
            Blueprint Tutorial | Stamina/Progress Bar Implementation | Forum

            Comment


              #7
              At least give MrFantasticGhost some credit if you just documented what he posted on Youtube 6 months before you joined. https://www.youtube.com/watch?v=G3e320pMIFo

              Comment


                #8
                It doesn't work for me... .. run speed remains constant even after releasing shift. sorry.. i am a complete noob.

                Comment


                  #9
                  Originally posted by VedXyte
                  It doesn't work for me... .. run speed remains constant even after releasing shift. sorry.. i am a complete noob.
                  (Also a newb, recently promoted from noob) I'm using the starter content and this is how I got sprint to work thanks to this thread. I too was unable to return to normal walk speed before googling to this thread.

                  The main difference is my blueprint adds calls to the animations in the starter kit. Click image for larger version

Name:	sprinting.png
Views:	1
Size:	165.2 KB
ID:	1126147
                  My first guess being unable to exit sprint is you are not re-setting the character walk speed back to the original speed. Check your float/integer variables to see if they have a defined number. Double check the links between nodes that they are not repeating or looping on eachother

                  The InputAction Sprint event is created by making the Input in the Project Settings under the Input Tab. You'll need to create a new Input called Sprint and define the keybind for it. Open your character blueprint and add the InputAction Sprint. Drag from the event and search Max Walk Speed under the category Character Movement. You'll get what my screencap shows as "Set Max Walk Speed + Target = Character Movement". Create a new variable float/integer and call it Sprint Speed. Do the same but on the Released and create a new variable float/integer and call it Walk Speed. Compile and set Walk speed to the default (600.0) and set Sprint Speed to whatever speed you want while sprinting.
                  Last edited by Xnar; 04-07-2017, 11:06 PM.

                  Comment


                    #10
                    Originally posted by ConnorTheScot View Post
                    Hi there!

                    Below is a beginner friendly (i hope) tutorial i have put together on how to implement a very basic sprinting system into your project.
                    The tutorial is broken down into sections which should allow for easy following and brief explanations are provided for those who may be new to the Unreal Editor.

                    I am aware that there are various tutorials/blueprint examples on the UE4 wiki, UE forums and Youtube which explains how to implement this much faster, however after this tutorial i shall also be submitting my stamina decay/regen tutorial which will build on the information provided in this tutorial.

                    I hope the tutorial helps those who are new to the editor, if you get confused at any point or something is not working as intended then let me know.

                    Additionally i have included an image at the end of the tutorial to act as a sort of TLDR, which provides a snapshot of the Blueprint setup if you wish to skip reading the less fun parts .

                    If you think the tutorial is long winded or would be better presented an alternative way, please do let me know.

                    Hope this helps somebody!

                    ------

                    1.0 - Project Creation
                    1.1 - The first thing we want to do when we open Unreal Editor 4 is create a new project using the Third Person Game example with starter content. I have named my project ‘Sprint Tutorial’, however for sake of implementation your project does not necessarily need to have the same name.

                    2.0 - Input Actions
                    2.1 - The first thing we must do once our project has been created is set up our new input actions that are going to allow our character to sprint. To do this we must go into the project settings, which can be accessed along the top of the editor screen.


                    2.2 - Within the Input section of our project settings, we are going to create a new action mapping bound to the Left Shift key. This action map will be named Sprint.


                    3.0 - Sprint Blueprint
                    3.1 - Now that we have our action mapping set, we must now create two variables within our ThirdPersonCharacter blueprint which will set the walk speed and run speed of our character.

                    3.1.1 - With the ThirdPersonCharacter event graph open, nagivate to the variables of the blueprint which are typically on the left side of the editor. Click the + to create two new variable called Walk Speed and Run Speed. These variables will as standard be Boolean variables (true or false), however for our purposes we must ensure that they are Float variables (decimal numbers). To change our variables from Boolean to Float we can click on them and change their Variable Type to Float in the details panel at the right side of the editor.


                    Now we have our variables created, we must now set their default values, to allow us to do that we must first compile our blueprint. With that done, if we click on either of the variables we can set their default values in the details pane (typically on the right side of the editor). In this instance, I have set my walk speed to 175.00 and run speed to 600.00.


                    3.2 - With our variables now created and set, we must now work in the ThirdPersonCharacter blueprint to create our sprinting action.

                    3.2.1 - The first thing we must do right click and create our InputAction Sprint node. We can do this by right clicking anywhere in our event graph and typing ‘Input Action Sprint’.

                    3.2.2 - Now we must get a reference to our character movement as this allows us to manipulate the default movement values of our character. To get this reference, either drag and drop it from the components section of the editor (typically top left of the screen) or right click in the event graph and type ‘get character movement’ and add the Get Character Movemenent node.


                    3.2.2 Now that we have reference to the character movement, we can now manipulate the max walk speed of our character. We can do this by adding a Set Max Walk Speed node to our event graph, this is done by dragging a wire from our character movement reference and adding the Set Max Walk Speed node.


                    3.2.3 - We must now join our InputAction Sprint Pressed pin to our Set Max walk Speed node pin. Also we must set the value of our Max Walk Speed pin when our InputAction Sprint is pressed, we do this by referencing the ‘Run Speed’ variable we created in part 3.1.1. This can be done either by dragging and dropping the node from our variable sections on the left side of the editor or by right clicking and typing ‘get run speed’ and adding the Run Speed node. Now drag a wire from the Run Speed node and connect it to the Max Walk Speed pin of our Set Max Walk Speed node.


                    3.2.4 - Now if we compiled and tested our project, our characters max walk speed changes from 175.00 to 600.00 when our InputAction Sprint is pressed, but nothing happens when we release our InputAction. The desired effect is for our character to return back to a walking speed when released and to do this we insert a very similar set of nodes that we used for the InputAction Sprint Pressed pin. We can copy the Set Max Walk Speed node and link this to the InputAction Sprint Released pin. Then we must set a value for the max walk speed when released just like in 3.2.3. We will do this by creating a reference to our Walk Speed variable we created earlier and linking this to our Max Walk Speed pin. Multiple wires can be taken from the character movement reference, so again link this to our target of the Set Max Walk Speed Node.


                    3.2.5 - The last thing we must add within our blueprint is an Event BeginPlay node which we will use to set the Max Walk Speed of our character when our game is first started. These nodes will be set up similar to the previous set of nodes, where we are setting the Max Walk Speed by referencing our Walk Speed variable.


                    4.0 - Compile and Test
                    4.1 - Now we can compile our blueprint and test our project to ensure our sprint is working as intended. When in play, we can press and hold the shift key to increase our characters movement speed and when released our character returns back to a walking speed.

                    TLDR
                    Set up your Event Graph as per the below image and ensure your variables have been set as per section 3.0.

                    there is one big problem with this. the game starts with default walk speed before shift is pressed. So on starting game, the character starts to run, and after shift pressed once this work. how to change the default max walk speed?

                    Comment


                      #11
                      I might be a bit late, but this is amazingly documented! Thanks!

                      Comment


                        #12
                        I often think these kind of things are difficult then I see this and realize it isn’t as hard as I thought. Good i for thank you.

                        Comment


                          #13
                          This is great! Thanks for documenting and sharing! Helped me a lot (also added slower walk speed when holding shift!)

                          Comment

                          Working...
                          X