Hi, folk!
I’m trying to understand how UE works and, for that, I tried implementing some basic actors, such as a Pawn that has a FPS Camera to it. But I get a strange issue.
My camera goes nuts and starts to roll around, making the ground seem vertical. It’s barrel rolling. How do I stop that?
Here’s an image:
NOTE: I’m using a Pawn class as parent and using the old input version.
Here’s my Cpp code!
// PlayerCharacter.cpp
void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &APlayerCharacter::MoveForward);
PlayerInputComponent->BindAxis(TEXT("MoveRight"), this, &APlayerCharacter::MoveRight);
PlayerInputComponent->BindAxis(TEXT("RotateCamera"), this, &APlayerCharacter::RotateCamera);
PlayerInputComponent->BindAxis(TEXT("LookUp"), this, &APlayerCharacter::LookUp);
}
void APlayerCharacter::RotateCamera(float AxisValue)
{
FRotator NewRotation = Camera->GetRelativeRotation();
NewRotation.Yaw += FMath::Clamp(AxisValue, -1.0f, 1.0f);
Camera->SetRelativeRotation(NewRotation);
}
void APlayerCharacter::LookUp(float AxisValue)
{
FRotator NewRotation = Camera->GetRelativeRotation();
NewRotation.Pitch += FMath::Clamp(AxisValue, -1.0f, 1.0f);
Camera->SetRelativeRotation(NewRotation);
}
What’s wrong with my code? How do I “clamp” my movement to the Y and X axis?
Thanks for the attention!