Hey guys! I hope that you are doing fine.
I am trying to make an FPS game and the tutorials that I watch suggest that I should attach the ‘Mesh1P’ to the camera component: Mesh1P->SetupAttachment(CameraComponent);
But the UE4 FPS project ‘The Shooter Game’ suggest rotating the mesh in tick function:
void AShooterCharacter::OnCameraUpdate(const FVector& CameraLocation, const FRotator& CameraRotation){
USkeletalMeshComponent* DefMesh1P = Cast<USkeletalMeshComponent>(GetClass()->GetDefaultSubobjectByName(TEXT("PawnMesh1P")));
const FMatrix DefMeshLS = FRotationTranslationMatrix(DefMesh1P->GetRelativeRotation(), DefMesh1P->GetRelativeLocation());
const FMatrix LocalToWorld = ActorToWorld().ToMatrixWithScale();
// Mesh rotating code expect uniform scale in LocalToWorld matrix
const FRotator RotCameraPitch(CameraRotation.Pitch, 0.0f, 0.0f);
const FRotator RotCameraYaw(0.0f, CameraRotation.Yaw, 0.0f);
const FMatrix LeveledCameraLS = FRotationTranslationMatrix(RotCameraYaw, CameraLocation) * LocalToWorld.Inverse();
const FMatrix PitchedCameraLS = FRotationMatrix(RotCameraPitch) * LeveledCameraLS;
const FMatrix MeshRelativeToCamera = DefMeshLS * LeveledCameraLS.Inverse();
const FMatrix PitchedMesh = MeshRelativeToCamera * PitchedCameraLS;
Mesh1P->SetRelativeLocationAndRotation(PitchedMesh.GetOrigin(), PitchedMesh.Rotator());
}
I tried both methods and attaching the mesh to the camera is smooth and I have no problems with weapon Aiming. When I do the OnCameraUpdate
, the animations are jittery and my Aiming function acts weird!
Because its working like I want, I’m sticking to the first approach but it still bugs me! the first method is easier and it works just fine, why Epic developers choose to do the later? any advice would be appreciated. Thank you.