How do I force the character to use the camera class I have made and not the integrated FollowCamera in the third person template.
you need to make a player controller class, and in the constructor of player controller class you can write:
AYourGamePlayerController::AYourGamePlayerController(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP)
{
PlayerCameraClass = AYourCamera::StaticClass();
}
Then you need to get rid of the camera that is created in the third person character constructor code:
YourGameCharacter.cpp
// Create a follow camera
FollowCamera = PCIP.CreateDefaultSubobject(this, TEXT("FollowCamera"));
Components.Add(FollowCamera);
// Create a camera boom (pulls in towards the player if there is a collision)
CameraBoom = PCIP.CreateDefaultSubobject(this, TEXT("CameraBoom"));
CameraBoom->AttachTo(RootComponent);
Components.Add(CameraBoom);
// The camera follows at this distance behind the character
CameraBoom->TargetArmLength = 900.0f;
// and offset by this amount
CameraBoom->SocketOffset = FVector::ZeroVector;
// Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
// instead of the camera
FollowCamera->AttachTo(CameraBoom, USpringArmComponent::SocketName);
CameraBoom->bUseControllerViewRotation = true;
FollowCamera->bUseControllerViewRotation = false;
Thats what I did. As you can see here `AFrontiersCamera::AFrontiersCamera(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
bAlwaysApplyModifiers = true;
}
void AFrontiersCamera::UpdateViewTarget(FTViewTarget& OutVT, float DeltaTime)
{
FVector Loc, Pos, HitLocation, HitNormal, EyeLoc, FinalPos;
FRotator Rot, EyeRot;
FMath math = FMath();
AFrontiersCharacter* TypedTarget = Cast(OutVT.Target);
//It should be header file, but for now it will work.
FVector LowOffset = FVector(-100.0f, 0, 20.0f);
FVector MidOffset = FVector(-200.0f, 200.0f, 100.0f);
FVector HighOffset = FVector(-50.0f, 0, 100.0f);
FVector FinalOffset = MidOffset;
OutVT.Target->GetActorEyesViewPoint(EyeLoc, EyeRot);
Loc = TypedTarget->GetActorLocation();
FVector const Offset = FVector(-150.0f, 0.0f, 0.0f);
FinalPos = Loc;
FinalPos += FRotationMatrix(EyeRot).TransformVector(FinalOffset);
OutVT.POV.Location = FinalPos;
OutVT.POV.Rotation = EyeRot;
}`
then my my character class
AFrontiersCharacter::AFrontiersCharacter(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP.SetDefaultSubobjectClass(ACharacter::CharacterMovementComponentName))
{
// Don't rotate when the controller rotates. Let that just affect the camera.
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
// Character moves in the direction of input...
CharacterMovement->bOrientToMovement = true;
// ...at this rotation rate
CharacterMovement->RotationRate = FRotator(360.0f, 360.0f, 360.0f);
// Create a follow camera
// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character)
// are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++)
}
//////////////////////////////////////////////////////////////////////////
// Input
void AFrontiersCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
check(InputComponent);
BIND_ACTION(InputComponent, "Jump", IE_Pressed, &AFrontiersCharacter::OnStartJump);
BIND_ACTION(InputComponent, "Jump", IE_Released, &AFrontiersCharacter::OnStopJump);
BIND_AXIS(InputComponent, "MoveForward", &AFrontiersCharacter::MoveForward);
BIND_AXIS(InputComponent, "MoveRight", &AFrontiersCharacter::MoveRight);
BIND_AXIS(InputComponent, "Turn", &AFrontiersCharacter::AddTurnInput);
BIND_AXIS(InputComponent, "LookUp", &AFrontiersCharacter::AddLookUpInput);
}
void AFrontiersCharacter::OnStartJump()
{
bPressedJump = true;
}
void AFrontiersCharacter::OnStopJump()
{
bPressedJump = false;
}
void AFrontiersCharacter::MoveForward(float Value)
{
if ((Controller != NULL) && (Value != 0.0f))
{
FRotator Rotation = Controller->GetControlRotation();
// Limit pitch when walking or falling
if (CharacterMovement->IsMovingOnGround() || CharacterMovement->IsFalling())
{
Rotation.Pitch = 0.f;
}
const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(0);
AddMovementInput(Direction, Value);
}
}
void AFrontiersCharacter::MoveRight(float Value)
{
if ((Controller != NULL) && (Value != 0.0f))
{
const FRotator Rotation = Controller->GetControlRotation();
const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(1);
AddMovementInput(Direction, Value);
}
}
then my playercontroller has that what u said above.
perhaps there is something wrong in the gameinfo? Thannks.