Код: Выделить всё
void APlayerCharacter::Move(const FInputActionValue& Value)
{
FVector2D InputVector = Value.Get();
if (IsValid(Controller))
{
//Get Forward Direction
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
const FVector ForwardVector = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
const FVector SideVector = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
// Add Movement Input
AddMovementInput(ForwardVector, InputVector.Y);
AddMovementInput(SideVector, InputVector.X);
}
}
Есть ли у кого-нибудь идеи, как мне это сделать, чтобы добиться желаемого поведения?
Я попробовал другой код:
Код: Выделить всё
void APlayerCharacter::MoveRightForward(const FInputActionValue& Value)
{
FVector2D InputVector = Value.Get();
if (IsValid(Controller))
{
// Get Forward and Side Directions based on the Yaw
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
const FVector ForwardVector = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
const FVector SideVector = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
// Apply movement only for positive input values (right and forward)
if (InputVector.X > 0.0f) // Right movement
{
AddMovementInput(SideVector, InputVector.X);
}
if (InputVector.Y > 0.0f) // Forward movement
{
AddMovementInput(ForwardVector, InputVector.Y);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... ementation
Мобильная версия