Hi guys!
I’m making Twin Stick game right now. I’m using the Anim Starter Pack and i have problem with animations. Everything works fine when player is moving forward but when i rotate him by mouse animations arent working correctly. I want to fix this issue but i dont how to do it. So im here. Here is short video which represents this issue: CLICK HERE and here is code which im using to rotate and move the player:
Rotate:
void ASCharacter::RotatePlayerByMouse()
{
FVector MouseLocation, MouseDirection, MouseLocationEnd, MouseRotation;
FHitResult HitResult;
UWorld* World = GetWorld();
APlayerController* PC = World->GetFirstPlayerController();
PC->DeprojectMousePositionToWorld(MouseLocation, MouseDirection);
//Make trace long so it hits anything nearby.
MouseLocationEnd = (MouseDirection * 10000) + MouseLocation;
//Stores settings for raycast.
FCollisionQueryParams TraceSettings;
FCollisionResponseParams TraceResponses;
ECollisionChannel Channel = ECollisionChannel::ECC_Visibility;
//Do trace. If it succeeds, complete calculations and set new rotation.
if (GetWorld()->LineTraceSingleByChannel(HitResult, MouseLocation, MouseLocationEnd, Channel, TraceSettings,
TraceResponses) == true)
{
//Calculate new rotation with actor's location and hit result.
FRotator NewRotation = UKismetMathLibrary::FindLookAtRotation(this->GetActorLocation(), HitResult.ImpactPoint);
this->SetActorRotation(FRotator(GetControlRotation().Pitch, NewRotation.Yaw, GetControlRotation().Roll));
}
}
Move:
void ASCharacter::MoveForward(float Value)
{
AddMovementInput(GetActorForwardVector() * Value);
}
void ASCharacter::MoveRight(float Value)
{
AddMovementInput(GetActorRightVector() * Value);
}