Hi, I need help with calculating the YAW to rotate my character to based on which keys are currently pressed.
Background:
I have a character (Orient rotation to movement) that does a roll animation when pressing Left Shift.
In the code for the LeftShit action Pressed, I need to check which directional keys are pressed at the time of Left Shift being pressed.
I know how to check if a key is pressed, but I don’t know what to do after that. How can I get the Yaw that I need to turn my character to before playing the rolling animation?
Here are some screenshots that help to explain what I’m after:
If somethings not clear, I can post a video or something to better try and explain.
Thanks
I’m using this as my current code but it’s not rotating my character to the current yaw.
const FRotator Rotation = caster->Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
UPlayerInput* input = caster->GetWorld()->GetFirstPlayerController()->PlayerInput;
if (input->IsPressed(EKeys::W))//TODO: Check actual MoveForwardKey
{
ForwardDirection = ForwardDirection * 1;
}
if (input->IsPressed(EKeys::S))//TODO: Check actual MoveForwardKey
{
ForwardDirection = ForwardDirection * -1;
}
if (input->IsPressed(EKeys::A))//TODO: Check actual MoveRightKey
{
RightDirection = RightDirection * -1;
}
if (input->IsPressed(EKeys::D))//TODO: Check actual MoveRightKey
{
RightDirection = RightDirection * 1;
}
FVector ForwardVector = UKismetMathLibrary::GetForwardVector(YawRotation) * ForwardDirection;
FVector RightVector = UKismetMathLibrary::GetRightVector(YawRotation) * RightDirection;
FVector FinalVector = ForwardVector + RightVector;
return FinalVector.Rotation().Yaw;