Guest User

Untitled

a guest
Apr 21st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #include "ABCharacter.h"
  4. #include "ABAnimInstance.h"
  5. #include "DrawDebugHelpers.h"
  6.  
  7. // Sets default values
  8. AABCharacter::AABCharacter()
  9. {
  10. ....
  11. AttackRange = 200.0f;
  12. AttackRadius = 50.0f;
  13. }
  14.  
  15. /* ... */
  16.  
  17. void AABCharacter::AttackCheck()
  18. {
  19. FHitResult HitResult;
  20. FCollisionQueryParams Params(NAME_None, false, this);
  21. bool bResult = GetWorld()->SweepSingleByChannel(
  22. HitResult,
  23. GetActorLocation(),
  24. GetActorLocation() + GetActorForwardVector() * AttackRange,
  25. FQuat::Identity,
  26. ECollisionChannel::ECC_GameTraceChannel2,
  27. FCollisionShape::MakeSphere(AttackRadius),
  28. Params);
  29.  
  30. #if ENABLE_DRAW_DEBUG
  31.  
  32. FVector TraceVec = GetActorForwardVector() * AttackRange;
  33. FVector Center = GetActorLocation() + TraceVec * 0.5f;
  34. float HalfHeight = (AttackRange + AttackRadius) * 0.5f;
  35. FQuat CapsuleRot = FRotationMatrix::MakeFromZ(TraceVec).ToQuat();
  36. FColor DrawColor = bResult ? FColor::Green : FColor::Red;
  37. float DebugLifeTime = 5.0f;
  38.  
  39. DrawDebugCapsule(GetWorld(),
  40. Center,
  41. HalfHeight,
  42. AttackRadius,
  43. CapsuleRot,
  44. DrawColor,
  45. false,
  46. DebugLifeTime);
  47.  
  48. #endif
  49.  
  50. if (bResult)
  51. {
  52. if (HitResult.Actor.IsValid())
  53. {
  54. ABLOG(Warning, TEXT("Hit Actor Name : %s"), *HitResult.Actor->GetName());
  55. }
  56. }
  57.  
  58. }
Add Comment
Please, Sign In to add comment