I am looking to either trace a sphere or get the overlapping actors of a subcomponent sphere on a character class in order to create a melee combat system.
Have had no luck with either approach, anyone have an example of this?
I am looking to either trace a sphere or get the overlapping actors of a subcomponent sphere on a character class in order to create a melee combat system.
Have had no luck with either approach, anyone have an example of this?
this didnt do anything…
construct:
HitSphere = CreateDefaultSubobject<USphereComponent>(TEXT(“SphereHit”));
HitSphere->AttachTo(GetMesh());
HitSphere->bGenerateOverlapEvents = true;
HitSphere->OnComponentBeginOverlap.AddDynamic(this, &ABearGameCharacter::OnHitSphereOverlapBegin);
function
void ABearGameCharacter::OnHitSphereOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
Jump();
}
K finally figured it out, worked with a trace like this:
FCollisionQueryParams FCQP = FCollisionQueryParams(FName(TEXT("RV_Trace")), true, this);
FCQP.bTraceComplex = true;
FCQP.bTraceAsyncScene = false;
FCQP.bReturnPhysicalMaterial = false;
FCQP.AddIgnoredActor(BearPawn);
//Needs at least one unit of movement, guessing it sweeps to get the actors
FVector Start = BearPawn->GetActorLocation() + BearPawn->GetActorForwardVector() * 26; //This class works like a weapon so BearPawn is the owning pawn
FVector End = Start + BearPawn->GetActorForwardVector() * 1;
FCollisionResponseParams FCRP = FCollisionResponseParams(ECR_Overlap);
TArray<FHitResult> Hits;
GetWorld()->SweepMultiByChannel(Hits, Start, End, FQuat(), ECC_Pawn, FCollisionShape::MakeSphere(10), FCQP, FCRP);
if(Hits.Num() > 0)
{
for(int i = 0; i < Hits.Num(); i++)
{
//Do What you need to all the overlapping actors
}
}