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.
AtPlayer.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "AtPlayer.generated.h"
/**
*
*/
UCLASS()
class TRAFFICSIMRUNTIME_API AAtPlayer : public APlayerController
{
GENERATED_BODY()
AAtPlayer();
};
AtPlayer.cpp
// 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.
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.
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”.