Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

What is the correct way to set the speed of the character possessed by a player controller?

I have looked everywhere for how to adjust the speed of the player and can't find anything with a clear and complete answer.

I came up with the following custom player controller code from the other posts I've looked at but when I compile it the editor crashes.


 #pragma once
 #include "CoreMinimal.h"
 #include "GameFramework/PlayerController.h"
 #include "AtPlayer.generated.h"
 class TRAFFICSIMRUNTIME_API AAtPlayer : public APlayerController


 // Fill out your copyright notice in the Description page of Project Settings.
 #include "AtPlayer.h"
 #include "Runtime/Engine/Classes/GameFramework/Character.h"
 #include "Runtime/Engine/Classes/GameFramework/CharacterMovementComponent.h"
 AAtPlayer::AAtPlayer() {
     UE_LOG(LogTemp, Display, TEXT("Using custom player controller"));
     GetCharacter()->GetCharacterMovement()->MaxWalkSpeed = 3;

All I want is for the player to be able to move faster in game since I have a large map and it can take a long time to travel.

Product Version: UE 4.18
more ▼

asked Aug 27 '18 at 02:44 PM in C++ Programming

avatar image

Paul AtLink
1 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

I can't really pretend to know the universally "correct" way but my approach would be to set the highest speed I need in the pawn class. (from the editor)

Then if I need the AI to go slower I would make it drive the pawn at half the speed.

more ▼

answered Aug 27 '18 at 02:56 PM

avatar image

1.3k 6 5 9

avatar image Paul AtLink Aug 27 '18 at 03:05 PM

So put a pawn in the scene rather than spawning from the player start? Currently my pawn is spawning from the player start since that is the default mode. I couldn't find a way in editor to adjust the speed from the editor.

avatar image dZh0 Aug 28 '18 at 11:51 AM

It is not necessary to put it in the scene. It can be spawned with different max speed from the player start.

If you don't have a blueprint class of your AtPlayer.cpp, make one. In the blueprint class (in the Content Browser) you can set the class defaults including all inherited values from the character movement component like ruining speed, swimming speed etc.

If you need different pawns with different settings just make a child blueprint class with different defaults.

From that point on you should be able to spawn it with the set value in place.

avatar image Paul AtLink Aug 28 '18 at 01:27 PM

Is there not a way to do it using C++?

avatar image dZh0 Aug 28 '18 at 02:27 PM

The "correct" way for me is to expose your C++ classes to blueprint in order to be used in the editor and to enable their parameters to be set from there.

Unreal blueprints go hand in hand with the C++ implementation.

Then again, you can always set them all in the constructor. However, I would not consider this approach anywhere near "correct".

avatar image Paul AtLink Aug 28 '18 at 07:08 PM

Ok, thanks.

avatar image dZh0 Aug 29 '18 at 12:03 AM

I stand corrected on my last sentence.

All speeds are actually set in the constructor of UCharacterMovementComponent and so they will only define the default values of your blueprint class.

If you want to change the speed you should access the character's movement component (which is private) and there is a MaxWalkSpeed public variable.

Still all C++ examples and project templates use a blueprint class derived from C++ for their charter.

I still stand by my initial approach to use the character to set the speed and avoid using the controller.

avatar image Paul AtLink Aug 29 '18 at 01:18 PM

ah, that makes sense. Thanks for the help, I think I have a much better idea where to start now.

avatar image dZh0 Aug 30 '18 at 09:09 AM

Glad I can help. Sorry If I threw you off tracks for a moment.

I am still learning too :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question