Sprint and Speed

Documentation Unreal Engine Player Combat Movement

UPC Sprint makes the character walk by default and sprint on a button, held or tapped, for a stamina cost. Gameplay tags slow it, and a sprint, a slow and a speed upgrade combine.


Set it up

5 minutes
  1. 1

    Add the sprint to the character

    The demo character BP_UPC_Character already has a UPC Sprint component; skip to step 3 there. In your own character Blueprint, Add one (UPC Character Base has none). The character walks at 250 cm/s and sprints at 600.
  2. 2

    Grant the sprint button

    The UPC Sprint Ability asks for a sprint when the button goes down (held, or tapped to latch); the component decides whether it happens. On a character built on UPC Character Base, add a row to its Starting Ability Set (such as the AbilitySet_MyCharacter from the Targeting quick start): Ability UPCSprintAbility, Input Tag UPC.Input.Sprint, Input Action IA_UPC_Sprint (Input). A character with its own parent has no such slot: add the same set to Ability Sets to Grant on its Default Item's Equippable fragment (Character Setup). The demo's AbilitySet_UPC_Default carries it already.
    The key comes from a mapping context on the player: the demo controller's IMC_UPC_Default maps IA_UPC_Sprint to Left Shift. On a controller of your own, add a context that maps it, or put one on the combat style's Input Mapping fragment.
  3. 3

    Give the character stamina

    On the character's UPC Vitals component (VitalsComponent on UPC Character Base), press + on Vitals for a stamina row that refills (Vitals); skip this on a character that has one.
    VitalsComponent
    ▾Vitals > Index [1]
    Vital Tag 
    Max Value 
    Regen Rate Per Second0.0
    Regen Delay Seconds0.0
    100 stamina, refilling 15 a second from 1.5 seconds after it last changed.
  4. 4

    Make sprinting cost stamina

    On the UPC Sprint component, set Stamina Vital to UPC.Vital.Stamina.
    UPCSprint
    ▾Stamina
    Stamina VitalNone
    Stamina Drain Per Second 
    Min Stamina to Start 
    Sprinting spends 10 points a second and needs at least 10 in the vital to start.
  5. 5

    Press Play and hold Left Shift while moving

    The character speeds up and stamina drains. Out of stamina it walks; holding the button, it sprints again once 10 points come back.

Tune the sprint

Details
Sprint
UPC
Sprint
Walk Speed
250
Sprint Speed
600
Speed Blend Seconds
0.35
Min Input Strength
0.5
Max Sprint Angle
180
Blocked Tags
3 Gameplay Tags
UPC.State.Blocking
UPC.State.Encumbered
UPC.State.Overburdened
Stop Grace Seconds
0.2
Stamina
Stamina Vital
None
Stamina Drain Per Second
10
Min Stamina to Start
10
Advanced
Request Tag
UPC.State.SprintRequested
Sprinting Tag
UPC.State.Sprinting
A new UPC Sprint before step 4: Stamina Vital is None, so sprinting costs nothing, as on the demo character. A component added by hand is named UPCSprint.
SettingDoes
Walk Speed, Sprint SpeedThe two paces in cm/s. Walk Speed replaces the movement component's Max Walk Speed.
Speed Blend SecondsHow long the change between them takes; 0 changes at once. A combat style's Movement fragment sets it as Sprint Blend Seconds.
Min Input StrengthHow far the player pushes the stick to sprint, 0 to 1; a key counts as fully pushed.
Max Sprint AngleHow far from the facing the movement may point and still sprint. 180 sprints every way; 75 walks a strafe.
Blocked TagsTags that hold the character at walking pace, such as UPC.State.Blocking for a raised guard.
Stop Grace SecondsHow long without movement input counts as stopped, ending a tapped sprint.
Stamina VitalThe vital a sprint spends. None makes sprinting free.
Stamina Drain Per Second, Min Stamina to StartPoints spent each second, and needed to start. A running sprint carries on until the vital is empty.
A tap shorter than the ability's Latch Tap Seconds (0.25 s) keeps the sprint on after release, until the character stops or the button is pressed again; change it in a Blueprint child of UPCSprintAbility (0 ends every sprint on release).
Run without a button by adding UPC.State.SprintRequested, such as from a combat style's Gameplay Tags fragment.

React to sprinting

The character carries UPC.State.Sprinting at sprint pace, for a camera state (Camera) or a sprint attack's transition. On Sprint Changed fires as a sprint starts or stops, and Is Sprinting reads it.

Slow the character by tag: UPC Speed Modifier

Add a UPC Speed Modifier component and fill Speed Scale by Tag with a tag and its multiplier: 0.2 leaves a fifth of the speed, 0 holds the character still. Tags multiply (0.5 beside 0.2 leaves a tenth), and a parent tag covers its children. A UPC State Tag Window holding the tag, such as UPC.State.Staggered across a stumble montage, times the slow to the animation (Animation Integration).
Details
UPCSpeedModifier
UPC
Movement
Speed Scale by Tag
6 Map elements
UPC.State.Staggered
0.2
UPC.State.Blocking
0.4
UPC.State.Swift
1.05
UPC.State.Encumbered
0.85
UPC.State.HeavilyEncumbered
0.0
UPC.State.Overburdened
0.0
The demo character slows to a fifth of its speed while staggered and to 40 percent while its guard is up. Carrying 70 percent of the weight limit slows it to 85 percent; carrying the limit or more holds it still. A value above 1 speeds it up: UPC.State.Swift adds 5 percent.
NodeDoes
Set Speed Scale for Tag, Remove Speed Scale for TagChange what a tag means during play.
Add Speed Modifier, Remove Speed Modifier, Has Speed Modifier, Clear Speed ModifiersHold a multiplier under an id of your own, for a slow no tag stands for; no ability system needed.
Get Current Speed Scale, On Speed Scale ChangedThe combined multiplier, 1 when nothing applies, and an event as it changes.

How speed changes stack

A sprint, a slow and a move that roots the character all change one walk speed through the character's UPC Movement Modifiers, added when something first changes movement:
Starts fromEnds at the walk speed in force
1
The character's own walk speed
Max Walk Speed on the movement component, or Set Base Value
What every change works from while nothing replaces it.
2
The highest-priority override replaces it
UPC Sprint at pace priority 0; a Blueprint override at 100 by default
A character carrying a UPC Sprint has its pace here: Walk Speed or Sprint Speed, easing between them.
3
Every scale multiplies the result
UPC Speed Modifier, a node's Locomotion Modifier hook, a Blueprint's Scale Value
A slowing tag at 0.5 during a sprint at 600 gives 300.
To change the speed from a Blueprint:
  • A permanent upgrade with a UPC Sprint: set the Sprint component's Walk Speed and Sprint Speed, such as 275 and 660 for +10 percent. The Sprint component holds the walk speed, so a Set Base Value would not show.
  • A permanent upgrade without one: Get Movement Modifiers, then Set Base Value on Max Walk Speed.
  • A change of your own for a while: Get Movement Modifiers, then Scale Value (Source: Self, Value: Max Walk Speed, Scale: 0.5) or Override Value. Later call Remove Modifiers with the same Source.
A Max Walk Speed written straight onto the movement component lasts only until the next change.

Debug it

Log LogUPCCharacter Verbose raises the sprint's log.
AdvancedHow a sprint is decided
The ability holds UPC.State.SprintRequested while the button is down. The UPC Sprint component checks every frame whether the character may sprint:
Checked firstChecked last
1
Something asks for a sprint
UPC.State.SprintRequested on the character
The UPC Sprint Ability holds it while its button is down, or after a quick tap until the character stops. Anything else that adds the tag asks the same way.
2
The character is on the ground
In the air the pace it left the ground with holds
A jump or a fall neither starts nor ends a sprint.
3
The stick is pushed far enough, the right way
Min Input Strength, Max Sprint Angle
Half way by default; a key counts as fully pushed. Every direction sprints until Max Sprint Angle is lowered.
4
Nothing holds it at walking pace
Blocked Tags
Any one of the tags on the character keeps it walking, such as a raised guard.
5
There is stamina to spend
Stamina Vital, Min Stamina to Start
Starting takes Min Stamina to Start; a running sprint goes on until the vital is empty. No Stamina Vital makes sprinting free.
Every check passing eases the character up to Sprint Speed over Speed Blend Seconds; one failing eases it back to Walk Speed. The character carries UPC.State.Sprinting while it runs at sprint pace.
  • The sprint's pace is a walk speed override at the lowest priority, and slows are scales, so the pace keeps easing under an attack that roots the character and resumes where the ease has got to when the attack ends.
  • The UPC Input Mapping component sends the second press into the running sprint. Input that starts the ability again instead gets a warning, and the sprint goes on.
  • Is Sprint Requested is true while something asks for a sprint, allowed or not; Get Current Speed gives the pace as it eases. Request Tag and Sprinting Tag, under the component's advanced arrow, rename the two tags.
AdvancedSpeed Modifier in detail
  • An entry below 0 is ignored, so a slow cannot turn into a boost by multiplying with another. Set Speed Scale for Tag starts watching a new tag, and Add Speed Modifier with an id already held replaces its scale.
  • A Blueprint child of the component can override Combine Speed Scales to stack another way, such as the harshest only, and Apply Speed Scale to scale acceleration or turn rate too.
  • Bind to Owner Ability System watches the tags again for a pawn that builds or swaps its ability system after the component starts.
The demo
  • The demo player's Sprint lists UPC.State.Blocking, UPC.State.Encumbered and UPC.State.Overburdened in Blocked Tags; its stamina row holds 100 and refills 10 a second after 3 seconds.
  • The Freeflow style puts UPC.State.SprintRequested on in its Gameplay Tags fragment, so the character runs whenever the stick is pushed past half.
MultiplayerSprint and speed in multiplayer
  • The server and the player's machine run the same sprint rules from the same input and tags; a start or stop lands a fraction of a round trip apart, which smoothing absorbs. Only the player's machine ends a tapped sprint.
  • Other machines count the character as sprinting while it moves faster than Walk Speed. UPC.State.Sprinting sits only on the server and the player's own machine.
  • The stamina drain runs on the server.
  • Walk speed does not replicate; each machine works it out from the tags it sees, and the Movement Modifiers replicate nothing. Add a Speed Modifier's tag through a gameplay effect or Add Replicated Loose Gameplay Tag, or the server and the player disagree about the speed.
C++C++
  • UUPCSprintComponent::CanSprint is a BlueprintNativeEvent; HasStopped() and the native OnStopped report the stop a tapped sprint waits for.
  • UUPCSprintAbility carries UPC.Ability.ForwardInputWhileActive in its asset tags, which sends the second press into the running instance.
  • UUPCMovementModifierComponent::FindOrAdd(AActor*) is Get Movement Modifiers; OverrideValue, ScaleValue, OverrideFlag, RemoveModifiers(Source) and SetBaseValue work per source. The sprint overrides at UPCMovementPriority::Pace (0), a style at UPCMovementPriority::Style (100), the approach's facing hold at UUPCMovementModifierComponent::FacingPriority (1000).
  • UUPCSpeedModifierComponent::CombineSpeedScales_Implementation and ApplySpeedScale_Implementation are the override points.
AdvancedTroubleshooting
Warning or symptomFix
...does nothing: the owner has no Character Movement componentPut the component on a character.
...heard the press meant to end a latched sprint as a new startSend the Sprint input through the UPC Input Mapping component, or with Forward Input Event to Granted Ability while the sprint runs.
The button does nothingGrant the ability on the input, add a UPC Sprint, or check Blocked Tags.
The character sprints only sometimesCheck Min Input Strength and Max Sprint Angle.