Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "ABCharacter.h"
- #include "ABAnimInstance.h"
- #include "DrawDebugHelpers.h"
- // Sets default values
- AABCharacter::AABCharacter()
- {
- ....
- AttackRange = 200.0f;
- AttackRadius = 50.0f;
- }
- /* ... */
- void AABCharacter::AttackCheck()
- {
- FHitResult HitResult;
- FCollisionQueryParams Params(NAME_None, false, this);
- bool bResult = GetWorld()->SweepSingleByChannel(
- HitResult,
- GetActorLocation(),
- GetActorLocation() + GetActorForwardVector() * AttackRange,
- FQuat::Identity,
- ECollisionChannel::ECC_GameTraceChannel2,
- FCollisionShape::MakeSphere(AttackRadius),
- Params);
- #if ENABLE_DRAW_DEBUG
- FVector TraceVec = GetActorForwardVector() * AttackRange;
- FVector Center = GetActorLocation() + TraceVec * 0.5f;
- float HalfHeight = (AttackRange + AttackRadius) * 0.5f;
- FQuat CapsuleRot = FRotationMatrix::MakeFromZ(TraceVec).ToQuat();
- FColor DrawColor = bResult ? FColor::Green : FColor::Red;
- float DebugLifeTime = 5.0f;
- DrawDebugCapsule(GetWorld(),
- Center,
- HalfHeight,
- AttackRadius,
- CapsuleRot,
- DrawColor,
- false,
- DebugLifeTime);
- #endif
- if (bResult)
- {
- if (HitResult.Actor.IsValid())
- {
- ABLOG(Warning, TEXT("Hit Actor Name : %s"), *HitResult.Actor->GetName());
- }
- }
- }
Add Comment
Please, Sign In to add comment