Hi! I’m trying to get a bit more control of my input and how it relates to my character’s movement.
But rotators and conversion math between rotation, floats, direction, vectors, etc isn’t my strong suit.
Currently, my character’s movement is simply:
W = +1 to XAxis
S = -1 to XAxis
A = +1 to YAxis
D = -1 to YAxis
Those inputs are fed to MovementInput like this.
FRotator Rotation = Controller->GetControlRotation();
if (GetCharacterMovement()->IsMovingOnGround() || GetCharacterMovement()->IsFalling())
{
Rotation.Pitch = 0.0f;
}
const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
AddMovementInput(Direction, XValue);
What I want is instead of treating X axis and Y axis separately. I wish to have the direction fed and influenced by both and interpolate towards the target direction set by the player. (which is only 8 directions)
So if the player is facing forwards, and presses S, I wish to have the direction interpolate from forwards to back along 180 yaw axis (rotation wise that is, I understand this would involve both X and Y when doing a direction?) Currently it only goes from +1x to -1x and ignores Y, how do I emulate/translate it into a rotation?
I can do the lerping part just fine, but I’m not sure how I would translate the X and Y axis into a combined direction?
TDLR: I have have the controller rotation.
I have an XAxis in float, and a YAxis in float which represents player input.
I wish to use these variables to interpolate a desired direction I can input into AddMovementInput(FVector Direction, float Scale)
The differences between forward vectors, rotation, local to world space etc and how to make use of them correctly are currently a bit hard for me to wrap my head around.