Talus
(Talus)
1
hi ,
always working on my Item system
I wondering How can I change a Line Trace into au spherical trace
Actually I have this for Item picking :
AItem* AResistanceCharacter::GetPickableInView()
{
FVector camLoc;
FRotator camRot;
if (Controller == NULL)
return NULL;
Controller->GetPlayerViewPoint(camLoc, camRot);
const FVector start_trace = camLoc;
const FVector direction = camRot.Vector();
const FVector end_trace = start_trace + (direction * MaxPickupDistance);
FCollisionQueryParams TraceParams(FName(TEXT("")), true, this);
TraceParams.bTraceAsyncScene = true;
TraceParams.bReturnPhysicalMaterial = false;
TraceParams.bTraceComplex = true;
FHitResult Hit(ForceInit);
GetWorld()->LineTraceSingle(Hit, start_trace, end_trace, USE_TRACE, TraceParams);
return Cast<AItem>(Hit.GetActor());
}
And I would change the LineTraceSingle by a spherical detection
Rama
(Rama)
2
#Sphere Trace
Here’s my code for a sphere trace, enjoy!
static FORCEINLINE bool VTraceSphere(
AActor* ActorToIgnore,
const FVector& Start,
const FVector& End,
const float Radius,
FHitResult& HitOut,
ECollisionChannel TraceChannel=ECC_Pawn
) {
FCollisionQueryParams TraceParams(FName(TEXT("VictoreCore Trace")), true, ActorToIgnore);
TraceParams.bTraceComplex = true;
//TraceParams.bTraceAsyncScene = true;
TraceParams.bReturnPhysicalMaterial = false;
//Ignore Actors
TraceParams.AddIgnoredActor(ActorToIgnore);
//Re-initialize hit info
HitOut = FHitResult(ForceInit);
//Get World Source
TObjectIterator< APlayerController > ThePC;
if(!ThePC) return false;
return ThePC->GetWorld()->SweepSingle(
HitOut,
Start,
End,
FQuat(),
TraceChannel,
FCollisionShape::MakeSphere(Radius),
TraceParams
);
}
eyosido
(eyosido)
3
Nice! Is there a way to make a cone raycast though, this is closer to how vision works, we see more objects far in the distance.