2017年1月16日月曜日

ターゲットが前か右か判定

ターゲットが前か右か判定

bool AThirdPersonCppCharacter::IsForward(const FVector& vTarget)
{
 bool bForward = false;

 FVector vDir = vTarget - GetActorLocation();
 vDir.Normalize();
 FVector vFwd = GetActorForwardVector();
 float fDot = FVector::DotProduct(vFwd, vDir);
 if ( fDot >= 0.f )
 {
  bForward = true;
 }
 return bForward;
}


bool AThirdPersonCppCharacter::IsRight(const FVector& vTarget)
{
 bool bRight = false;

 FVector vDir = vTarget - GetActorLocation();
 vDir.Normalize();
 FVector vRight = GetActorRightVector();
 float fDot = FVector::DotProduct(vRight, vDir);
 if ( fDot >= 0.f )
 {
  bRight = true;
 }
 return bRight;
}