Hello everyone There is a problem with Orient Rotation to movement. Everything seems to be done correctly, Use Controller Rotation Yaw is turned off. Maybe it’s some kind of UE bug? Please look at my code, maybe I made a mistake that I do not know about?
my cpp code:
#include “MyCharacter.h”
#include “Runtime/Engine/Classes/Kismet/GameplayStatics.h”
#include “MyAnimInstance_C.h”
// Sets default values
AMyCharacter::AMyCharacter()
{
// 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;
SpringArm = CreateDefaultSubobject(“SpringArm”);
SpringArm->SetupAttachment(RootComponent);
Camera = CreateDefaultSubobject<UCameraComponent>("Camera");
Camera->SetupAttachment(SpringArm);
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
GetCharacterMovement()->bOrientRotationToMovement = true;
GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f);
}
// Called when the game starts or when spawned
void AMyCharacter::BeginPlay()
{
Super::BeginPlay();
}
void AMyCharacter::FrowardBackMove(float Axis)
{
if ( (Controller != nullptr) && (Axis != 0.0f) )
{
FRotator Rotation = Controller->GetControlRotation();
FRotator YawRotation(0.f, Rotation.Yaw, 0.0f);
FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(Direction, Axis);
UE_LOG(LogTemp, Warning, TEXT("speed: "), GetCharacterMovement()->bOrientRotationToMovement);
}
}
void AMyCharacter::RightLeftMove(float Axis)
{
if ( (Controller != nullptr) && (Axis != 0.0f) )
{
FRotator Rotation = Controller->GetControlRotation();
FRotator YawRotation(0.f, Rotation.Yaw, 0.0f);
FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
AddMovementInput(Direction, Axis);
}
}
void AMyCharacter::LookUp(float Axis)
{
AddControllerPitchInput(Axis);
}
void AMyCharacter::LookRight(float Axis)
{
AddControllerYawInput(Axis);
}
// Called every frame
void AMyCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis(“LookRightLeft”, this, &AMyCharacter::LookRight);
PlayerInputComponent->BindAxis(“LookUpDown”, this, &AMyCharacter::LookUp);
PlayerInputComponent->BindAxis(“ForwardBackMove”, this, &AMyCharacter::FrowardBackMove);
PlayerInputComponent->BindAxis(“RightLeftMove”, this, &AMyCharacter::RightLeftMove);
}