I want my character not to move with the camera rotation. I have seen many solution for this issue but not for the c++ code
{
// Fill out your copyright notice in the Description page of Project Settings.
#include "John.h"
// Sets default values
AJohn::AJohn()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
GetCharacterMovement()->bOrientRotationToMovement = true;
GetCharacterMovement()->bIgnoreBaseRotation = true;
GetCharacterMovement()->RotationRate = FRotator(0.0f, 540.0f, 0.0f);
GetCharacterMovement()->JumpZVelocity = 600.0f;
GetCharacterMovement()->AirControl = 0.2f;
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(RootComponent);
CameraBoom->TargetArmLength = 300.0f;
CameraBoom->bUsePawnControlRotation = true;
FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
FollowCamera->bUsePawnControlRotation = false;
}
// Called when the game starts or when spawned
void AJohn::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AJohn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AJohn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis("Turn", this, &APawn::AddControllerYawInput);
PlayerInputComponent->BindAxis("LookUp", this, &APawn::AddControllerPitchInput);
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &ACharacter::StopJumping);
PlayerInputComponent->BindAxis("MoveForward", this, &AJohn::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &AJohn::MoveRight);
}
void AJohn::MoveForward(float Axis)
{
FRotator Rotation = Controller->GetControlRotation();
FRotator YawRotation(0.0f, Rotation.Yaw, 0.0f);
FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(Direction, Axis);
}
void AJohn::MoveRight(float Axis)
{
FRotator Rotation = Controller->GetControlRotation();
FRotator YawRotation(0.0f, Rotation.Yaw, 0.0f);
FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
AddMovementInput(Direction, Axis);
}
I have try to use the {IgnoreBaseRotation} but it is not fixing my problem…