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.
class TRAFFICSIMRUNTIME_API AAtPlayer : public APlayerController
// Fill out your copyright notice in the Description page of Project Settings.
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.
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.
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.
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.
Is there not a way to do it using C++?
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”.
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.
ah, that makes sense. Thanks for the help, I think I have a much better idea where to start now.
Glad I can help. Sorry If I threw you off tracks for a moment.
I am still learning too