I am working on a 2d platformer based off of the Side Scroller Template project and am trying to implement a wall slide mechanic but am having some trouble getting my line trace to work properly. My goal is to line trace from the Character’s position in the direction of inputted movement (either left or right) to see if a wall is in range so the Character can start wall sliding. However, I cannot seem to get my line trace detect a “hit” with any of the geometry I’ve tested this with (primitive geometry brushes, or basic static mesh shapes).
If anyone has any idea what the problem is and could provide any insight on what I’m doing wrong it would be extremely helpful. Here is the code I have to perform the line trace, (located in the MoveRight(float Value) function of my “PlatformerCharacter” class):
// Use Line Trace to check if player is touching a wall
const FName TraceTag("Wall Trace");
FCollisionQueryParams TraceParams = FCollisionQueryParams(TraceTag, true, this);
TraceParams.bTraceComplex = true;
TraceParams.bTraceAsyncScene = true;
TraceParams.bReturnPhysicalMaterial = false;
TraceParams.AddIgnoredActor(this);
// Declare and initialize struct to receive hit info
FHitResult HitResult(ForceInit);
// Calculate start and end points of line trace
FVector Start = GetActorLocation();
FVector End = Start;
float LineTraceLength = CapsuleComponent.Get()->GetScaledCapsuleRadius() + 50.0f; // want trace to be a little longer than capsule width to ensure wall is properly detected
if (Value > 0.0f)
{
// if player is inputting right movement check right (-y)
Start.Y -= LineTraceLength;
}
else if (Value < 0.0f)
{
// if player is inputting left movement check left (+y)
Start.Y += LineTraceLength;
}
DrawDebugLine(GetWorld(), Start, End, FColor::Blue, false, -1.0f, 1.0f, 5.0f);
// Fire the line trace
if (GetWorld()->LineTraceSingle(HitResult, Start, End, ECC_WorldStatic, TraceParams))
{
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Blue, TEXT("Hit Found"));
}