I’ve tried to get a basic camera set up for a character simply copying the template camera made by UE4. I don’t get how it works. I can get the whole character together with the camera/spring arm to turn around using APawn::AddControllerYawInput(), but it is supposed to not rotate the whole character.
The most problematic thing is, that APawn::AddControllerPitchInput() doesn’t seem to do anything. I’ve tried setting different inputs to activate it, and it simply won’t bother moving the camera. I then started a new project inserting almost nothing but the camera set up from the template,
From the Character .h,
UCLASS()
class SHOOTERSTRAT_API APlayerCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
APlayerCharacter();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
/************************************/
/* Camera */
/************************************/
/** Base turn rate, in deg/sec. Other scaling may affect final turn rate. */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera", meta = (AllowPrivateAccess = "true"))
float BaseTurnRate;
/** Base look up/down rate, in deg/sec. Other scaling may affect final rate. */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera", meta = (AllowPrivateAccess = "true"))
float BaseLookUpRate;
UPROPERTY(EditAnywhere, Category = "Camera")
class USpringArmComponent* PlayerCameraBoom;
class UCameraComponent* PlayerCamera;
/**
* Called via input to turn look up/down at a given rate.
* @param Rate This is a normalized rate, i.e. 1.0 means 100% of desired turn rate
*/
void LookUpAtRate(float Rate);
/** Returns CameraBoom subobject **/
FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return PlayerCameraBoom; }
/** Returns FollowCamera subobject **/
FORCEINLINE class UCameraComponent* GetFollowCamera() const { return PlayerCamera; }
};
From the Character .cpp,
APlayerCharacter::APlayerCharacter()
{
PrimaryActorTick.bCanEverTick = false;
// Set size for collision capsule
GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
// Configure character movement
GetCharacterMovement()->bOrientRotationToMovement = true;
GetCharacterMovement()->RotationRate = FRotator(0.0f, 540.0f, 0.0f);
GetCharacterMovement()->JumpZVelocity = 600.f;
GetCharacterMovement()->AirControl = 0.2f;
/************************************/
/* Camera */
/************************************/
// set our turn rates for input
BaseTurnRate = 45.f;
BaseLookUpRate = 45.f;
// Don't rotate when the controller rotates. Let that just affect the camera.
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
// Set up camera boom
PlayerCameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("PlayerCameraBoom"));
PlayerCameraBoom->AttachTo(RootComponent);
PlayerCameraBoom->TargetArmLength = 300.f; // Set boom length
// Rotate the arm based on the controller
PlayerCameraBoom->bUsePawnControlRotation = true;
PlayerCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("PlayerCamera"));
PlayerCamera->AttachTo(PlayerCameraBoom, USpringArmComponent::SocketName);
PlayerCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
}
I removed/changed some of the comments (And excluded some unnecessary parts of the code) because of formatting, but basically it’s just a copy of the 3rd person template camera.
I really don’t see what I am missing.
I thought the,
// Don't rotate when the controller rotates. Let that just affect the camera.
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
would make sure the character wouldn’t rotate along with the camera, but I guess I am wrong. It compiles fine, by the way.
In short: What is missing for the upwards rotation of the camera, and for the camera to rotation without affecting the character (When no movement input), like in the third person template?
Sorry if this is a vague question.