Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Line Trace with Level Geometry not Working

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;
             // 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"));

Product Version: Not Selected
more ▼

asked Jun 04 '14 at 04:16 AM in C++ Programming

avatar image

1 1 2 2

avatar image Alryco Jun 04 '14 at 04:31 AM

So I just tested this with another instance of PlatformerCharacter rather than a wall and it detected the collision, so it's just an issue with detecting a line hit with level geometry.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question