Idle 動畫導致 人物瞄準鬼畜問題
阿新 • • 發佈:2020-10-14
人物瞄準近距離的位置會出現鬼畜情況
根據程式碼分析,發現如果Diretion的起始位置為MuzzleLoc時 人物瞄準近距離時會鬼畜,而使用PawnLoc時則不存在這樣的問題,通過Log發現,Muzzle會因為人物動畫而產生一些微妙的位移,從而導致瞄準近距離時,人物的瞄準方向一直在變(距離越近,鬼畜越明顯)
void AHaliPlayerController::Turn(float Value) { if (Value != 0.f) { FHitResult TraceHitResult; GetHitResultUnderCursor(ECC_Visibility,true, TraceHitResult); FVector CursorLoc = TraceHitResult.Location; FVector MuzzleLoc = PlayerCharacter->GetMuzzleLocation(); FVector PawnLoc = PlayerCharacter->GetActorLocation(); FVector Direction = CursorLoc - MuzzleLoc; FRotator NewPawnRotation = Direction.Rotation();float PawnYaw = GetPawn()->GetActorRotation().Yaw; float NewPawnYaw = NewPawnRotation.Yaw; float NewPawnAngle = NewPawnYaw; float PawnAngle = PawnYaw; if (Value != 0.0f && PawnYaw != NewPawnYaw) { SetControlRotation(NewPawnRotation); } PlayerCharacter->SetAimPitch(Direction); } }