Hello everybody
Question is about how to properly implement movement for top down game.
I have movement of the character with WASD, but can’t understand how to make character to look where cursor is without changing vector of movement?
I have movement setup as PlayerMovementComponent with Mapping
void ADefaultCharacter::SetupPlayerInputComponent(UInputComponent *PlayerInputComponent) {
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis("MoveForward", this, &ADefaultCharacter::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &ADefaultCharacter::MoveRight);
}
Character moves properly but model only looks forward.
When I try rotating character where mouse points
void ADefaultCharacter::Tick(float DeltaTime) {
Super::Tick(DeltaTime);
APlayerController *PC = UGameplayStatics::GetPlayerController(GetWorld(), 0);
if (PC) {
FHitResult ResultHit;
PC->GetHitResultUnderCursor(ECC_GameTraceChannel1, true, ResultHit);
auto FindRotatorResult = UKismetMathLibrary::FindLookAtRotation(GetActorLocation(), ResultHit.Location);
SetActorRotation(FRotator(0.0f, FindRotatorResult.Yaw, FindRotatorResult.Roll));
}
}
and press “W” model starts moving to place where mouse is pointing.
Which is correct way to make character movement and view independent of each other?