Download

Convert primitive component to scene component?!

Hi, i have a line trace that returns a hit. I need to get the location of the hit component in world space. I am sure there must be a way to do this, can someone help me?

If there is no way to do this, how could i modify this function to return the same thing (it aplies the transform of the mesh to the bounding box of the mesh, projects the box on the XY plane and returns the corners of the formed square ) ?



TArray<FVector> CustomMath::GetWorldBoundingBoxPoints(UStaticMeshComponent* Mesh)
{
    TArray<FVector> Points;
    Points.Init(FVector::ZeroVector, 4);
    Mesh->GetLocalBounds(Points[0], Points[2]);
    Points[1].X = Points[2].X;
    Points[1].Y = Points[0].Y;
    Points[3].X = Points[0].X;
    Points[3].Y = Points[2].Y;
    FVector Loc = Mesh->GetComponentLocation();
    float RotYaw = Mesh->GetComponentRotation().Yaw;
    for (FVector Point : Points)
    {
        Point.RotateAngleAxis(RotYaw, FVector(0.0f, 0.0f, 1.0f));
        Point += Loc;
        Point.Z = 0.0f; //i don't need Z
    }

    return Points;
}


Well, it looks like simply casting to USceneComponent works perfectly. I assumed it doesen’t work because my code didn’t work, but the problem seems to be somewhere else. I think the problem is just me not understanding how GetLocalBounds work, but i’ll figure it out.

Normally you just do this:



if(GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, CollisionParams))  {    
    if(OutHit.bBlockingHit) {
       UE_LOG(LogTemp, Warning, TEXT("Impact Point: %s"), *OutHit.ImpactPoint.ToString()); //Should be world space x,y,z location of hit
    }
}