#Aura turn face to mouse direction/BP example
24 messages ยท Page 1 of 1 (latest)
You will maybe be interested in this post : #1198725838779195462 message
I encountered a problem when trying to move Aura into a different direction than the one she looks.
oh
Do you still need help?
I could achieve this using the mouse cursor
Here's my tips for you for when you want to implement something that is already working in BP
- Understand the flow and the sequences
- Hover over the BP functions, it will say for you what package / method is being used in each node
For example: if you hover the break hit result node, it will say: target is gameplay statics . This is the package / library that has that method.
So, in your C++, you can just call this method from GameplayStatics::
This is the code I have
Player Controller
void AZBPlayerController::Tick(float DeltaSeconds) {
Super::Tick(DeltaSeconds);
LookAt();
}
void AZBPlayerController::LookAt() {
// TraceTypeQuery1 = Visibility
FHitResult HitResult;
GetHitResultUnderCursorByChannel(TraceTypeQuery1, true, HitResult);
FVector HitLocation = HitResult.Location;
if (APawn* ControlledPawn = GetPawn<APawn>()) {
SetControlRotation(UKismetMathLibrary::FindLookAtRotation(ControlledPawn->GetActorLocation(), HitLocation));
}
}
Character
AZBCharacter::AZBCharacter() {
// // combat setup
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(RootComponent);
CameraBoom->TargetArmLength = 600.0f;
CameraBoom->bUsePawnControlRotation = false;
FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
FollowCamera->bUsePawnControlRotation = false;
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = true;
bUseControllerRotationRoll = false;
GetCharacterMovement()->bOrientRotationToMovement = false;
Combat = CreateDefaultSubobject<UCombatComponent>(TEXT("Combat"));
Combat->SetIsReplicated(true);
}
Notes:
In my case, I am rotating the player controller, not the character.
If you don't want your character rotating using the controller, you can change the SetControlRotation to ControlledPawn->SetActorRotation.
You also need to disable bUseControllerRotationYaw to false
The side effect of this is because the Pawn is not replicated, which means it will not work for multiplayer clients unless you manually replicate the rotation.
The advantage of using the player controller to replicate the rotation is because it's a UE built in feature that already replicates and has a good performance.
Hope it gives you a north
Thank you so much Paulo both code and tips ๐ค
Thanks @zenith oyster . I have implemented it too, and it works well.
But I am curious how did you manage the AAuraPlayerController::Move , when the character is not looking in the same direction as the camera ?
const FVector2d InputAxisVector = InputActionValue.Get<FVector2d>();
const FRotator Rotation = GetControlRotation();
const FRotator YawRotation(0.f, Rotation.Yaw, 0.f);
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
if (APawn* ControlledPawn = GetPawn<APawn>())
{
ControlledPawn->AddMovementInput(ForwardDirection, InputAxisVector.Y);
ControlledPawn->AddMovementInput(RightDirection, InputAxisVector.X);
}
The results are not great for me.
Okay I managed to crack something. We need to pass a reference to the spring arm camera of the character into the player controller and then use his rotation.
We need a reference to a component that will never rotate, and get its world rotation. So if it is not working with the spring arm, try the camera comp itself.
Inside AAuraPlayerController::Move
const FVector2d InputAxisVector = InputActionValue.Get<FVector2d>();
/*
//const FRotator Rotation = GetControlRotation();
const FRotator YawRotation(0.f, Rotation.Yaw, 0.f);
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
*/
const FRotator CameraRotation = CameraSpringArm->GetComponentRotation();
const FRotator CamYawRotation(0.f, CameraRotation.Yaw, 0.f);
const FVector CamRotForwardDirection = FRotationMatrix(CamYawRotation).GetUnitAxis(EAxis::X);
const FVector CamRotRightDirection = FRotationMatrix(CamYawRotation).GetUnitAxis(EAxis::Y);
if (APawn* ControlledPawn = GetPawn<APawn>())
{
ControlledPawn->AddMovementInput(CamRotForwardDirection, InputAxisVector.Y);
ControlledPawn->AddMovementInput(CamRotRightDirection, InputAxisVector.X);
}
WASD is now always in the "good" directions, from what we see, and I can turn the camera in any direction.
Thanks for the tips again ;p
Very cool!!! So when the character is facing to the bottom of the screen and you press W, what happens? Does it moves backwards or forward?
Well thats depend what you mean by backwards and forward ๐
If you mean by the character orientation, it is then backward if the character is facing the bottom of the screen
but I prefer to see it as the direction that you see, from the camera point of view. W is always toward the top of the screen, A toward the left, S toward the bottom, and D toward the right
the character will change its animation with the help of a blend tree, and 4 different animations. They are not very good (from mixamo) for this character, but it is kind of alright for a demo.
It is basically the controls of V Rising, that I just started playing ๐
can you share your blendtree?
Almost a year later (time sure fly fast), I rediscover this work. And I forgot to mention that you must check "Use Controller Desired Rotation" to be able to have a proper WSAD (such as VRising or Path of exile 2) :