Sprinting with Shift?

I’ve been working on adding sprinting with shift key to the shooter project, and I’ve run in to two issues.
First, when I set the shift key mapping up in DefaultInput like this the shift key has to be pressed before W for it to trigger.
+ActionMappings=(ActionName=“StartSprint”, Key=W, bShift=True);

Is there a way around this, so that when I press shift while pressing W it triggers it?

The next question is how to adjust the player movement speed. It looks like there are MovementComps now, but I can’t seem to find how the movement speed works right now.

As you noted, modifier keys are only valid if already down when the primary key is pressed. For your purposes I woud recommend an EnableSprint Action which sets a boolean on pressed and clears it on release. Then in your move forward code you would look at whether that boolean was true and manipulate the movement speed appropriately.

You would end up with something like so (will want to double check the key name and macro parameters might be a bit off as I’m doing this from memory):

+ActionMappings=(ActionName="EnableSprint", Key=Shift)

BIND_ACTION("StartSprint", IE_Pressed, &AMyPawn::EnableSprint);
BIND_ACTION("StartSprint", IE_Released, &AMyPawn::DisableSprint);

The CharacterMovementComponent has a GroundSpeed property. Manipulating that is one option, another would be to create a CharacterMovementComponent subclass and override the GetMaxSpeedModifier function.

Thanks a ton for that man!!

Also note that the next iteration of the Shooter Game sample has sprinting :slight_smile:

Thats great to hear. Will the shootergame be included with Rocket or will we have to download from FTP?

Ah…well I guess I will just have to wait for that then…

Hey there mate, I just experimented a bit and found a good solution to the problem.

First of all set up your inputs correctly under “Edit/Project Settings…/Engine/Input”. To make my approach work set it up like shown in the first picture:

http://s1.anyimg.com/img/mi5be9j/ShiftSprint_B.jpg

Then create your player Blueprint (Blueprint/Character). Make sure, that in your game Blueprint (Blueprint/Game Mode) the “Default Pawn Class” is set to your player Blueprint.
Once that is done creat two float variables, called “Var_SpeedForward” (set it to 1.7) and “Var_SpeedSideways” (set it to 1.3). And then recreate the scene of the following picture: (Fullscreenlink: [Fullscreenimage][2])

http://s1.anyimg.com/img/juvlzx8/ShiftSprint_A.jpg

What this all does is acutally pretty simple: the basic speed of your input is divided by a float value decreasing the default speed. If you then hit Shift while you’re moving (forward 1,7=fast, sideways 1,3=slightly faster) the values will be multiplied making your character move with maximum amount of speed. The clamp makes sure, that the multiplier never becomes zero which would disable any movement at all.

The very good part about this solution is, that if you use gamepad-inputs the sprinting speed blends smoothly between minimum and maximum depending on how intense you pull for instanc the Trigger-Buttons on your XBox Gamepad.

Hope this helps a bit, I might do a Video Tutorial about that in the near future if requested.

Greetings,
Dave