模仿黑魂锁定目标功能
Posted 湛蓝玫瑰
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了模仿黑魂锁定目标功能相关的知识,希望对你有一定的参考价值。
if (bLocked) { //取消锁定状态 bLockedTarget = false; bUseControllerRotationYaw = false; GetCharacterMovement()->bOrientRotationToMovement = true; } else { //锁定目标 bLockedTarget = true; bUseControllerRotationYaw = true; GetCharacterMovement()->bOrientRotationToMovement = false; //计算最近的目标 TArray<AActor*> TempActorArray; CharacterVisualField->GetOverlappingActors(TempActorArray); CharacterNearbyMonster.Reset(); for (int i = 0; i < TempActorArray.Num();++i) { AMonster *TempActor=Cast<AMonster>(TempActorArray[i]); if (TempActor&&!TempActor->IsPendingKill()) { CharacterNearbyMonster.Add(TempActor); } } if (CharacterNearbyMonster.Num()>0) { LockedTargetObject = CharacterNearbyMonster[0]; for (int i = 1; i<CharacterNearbyMonster.Num(); ++i) { FVector temp = ((AMonster*)CharacterNearbyMonster[i])->GetActorLocation() - GetActorLocation(); temp.Normalize(); FVector CurrenLockedTargetVector = LockedTargetObject->GetActorLocation() - GetActorLocation(); CurrenLockedTargetVector.Normalize(); if (FVector::DotProduct(CurrenLockedTargetVector, FollowCamera->GetForwardVector()) < FVector::DotProduct(temp, FollowCamera->GetForwardVector())) { LockedTargetObject = CharacterNearbyMonster[i]; } } } }
直接上代码,还有很多地方可以优化,仅供抛砖引玉,效果如图
以上是关于模仿黑魂锁定目标功能的主要内容,如果未能解决你的问题,请参考以下文章