When I play in editor with the custom character and I press the move right and left keys, D and A respectively, the character moves right and left… when facing north (default position in PIE). However, say I turn the character 90 degrees and try to move right or left the character moves in a different direction up, down. etc. I think this might be an issue with my code as I am relatively new to C++ although I have worked in C# before. Any help would be greatly appreciated. (First image is the .h file, the rest .cpp files)
Almost. In the MoveRight function, the pitchRotation should be yawRotation as well. Here’s what I used for a third person character.
void AHSurvivor::MoveForward(const float Value)
{
if (Value != 0.0f)
{
const FRotator ControlRotation = GetControlRotation();
const FRotator YawRotation = FRotator(0.0f, ControlRotation.Yaw, 0.0f);
// Get forward direction based on the yaw rotation
const FVector MoveDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(MoveDirection, Value);
}
}
void AHSurvivor::MoveRight(const float Value)
{
if (Value != 0.0f)
{
const FRotator ControlRotation = GetControlRotation();
const FRotator YawRotation = FRotator(0.0f, ControlRotation.Yaw, 0.0f);
// Get right direction based on the yaw rotation
const FVector MoveDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
AddMovementInput(MoveDirection, Value);
}
}
Thanks a lot, I’ll try this now
Edit: Thanks a lot this really helped