Hi there, sorry to bother you with this guys, but
Following Orfeas tutorial on simple line raycasting, I’m trying to mess around with the returned actor of the FHitResult struct.
I started with the First Person C++ template and wrote the basic parameters and function to use linetrace inside the fire method from the character class ( FHitResult Hit
and float RayLength
are declared within the header file).
void FirstPersonCharacter::OnFire() {
[...]
/* RAYCAST */
// Vectors
FVector StartLocation = FirstPersonCameraComponent->GetComponentLocation(); // Origin
FVector EndLocation = StartLocation + (FirstPersonCameraComponent->GetForwardVector() * RayLength); // End
// Params
FCollisionQueryParams CollisionParameters;
CollisionParameters.bFindInitialOverlaps = false; // Doesn't change anything whether it's true by default or false in my case
CollisionParameters.AddIgnoredActor(this);
//CollisionParameters.AddIgnoredActor(GetCapsuleComponent()->GetOwner()); // I also trid this
//CollisionParameters.AddIgnoredComponents(GetCapsuleComponent()->GetOwner()->GetComponents()); // And this
// Line trace
ActorLineTraceSingle(Hit, StartLocation, EndLocation, ECollisionChannel::ECC_WorldDynamic, CollisionParameters);
// Debug Line Draw
DrawDebugLine(GetWorld(), StartLocation, EndLocation, FColor::White, false, 10, 0, 1.f);
GLog->Log(Hit.ToString());
// Getting the hit actor
AActor* HitActor= Hit.GetActor();
}
By logging the FHitResult it tells me it hit the CollisionCylinder from attached to the character:
bBlockingHit:False bStartPenetrating:True Time:0.0 [...] Actor:FirstPersonCharacter_C_1 Component:CollisionCylinder
So how should I ignore the Character AActor ? Do I need to ignore both the Actor and his Components ?
I tried unsuccessfully both (separately) as you can tell from code.
And how should I get the instance of the character class ?
(Tried this
within the class and GetComponent()->GetOwner()
)
Thank you for your time. =)