Announcement

Collapse
No announcement yet.

Why wont my LineTrace Detect anything?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Why wont my LineTrace Detect anything?

    New comer from unity here. Raycasting/Line trace is probably one of the most important aspects of a game but for some reason my line trace doesnt seem to detect anything. I love the engine so far but this is kind of frustrating. Ive been stuck on this simple problem for a few days now. Basically the only purpose for my linetrace is to interact with an interface that says "hey theres something that can be touched here."

    I have a simple Interface class, in it are 3 UFUNCTION()'s : OnFocusStart, OnFocusEnd, and OnInteract. In the character class, there is a hidden variable called focusedActor that stores the current actor looked at fr convenience sake. (These names might be a little butchered but they are all implemented fine). Then I have an actor class that implements the interface.
    Click image for larger version

Name:	problem2.PNG
Views:	96
Size:	49.1 KB
ID:	1790391


    the problem lies within the linetrace function in my character class though. When I run it, I get the first debug and nothing else. It definitely ticks every frame because I have the tick function enabled, debug helper, AND when I place the debug outside of the we hit a new actor logic it updates every frame. Warning: the source code Im about to show may trigger some, but its for testing purposes only. I go back and cleanup after proof of concept

    Click image for larger version

Name:	problem3.PNG
Views:	60
Size:	58.9 KB
ID:	1790392

    I really dont get what im doing wrong. My first implementation is supposed to be a door teleport script. I have a large static mesh in place of a door model with a collider that blocks everything but nothing works.

    Click image for larger version

Name:	problem4.PNG
Views:	62
Size:	41.6 KB
ID:	1790393

    Is it a weird collision thing Im doing wrong? The root component system is really confusing. Even if I do a regular static mesh though theoretically it should debug as "found new object" anyways because its takes in any actor in the scene but no collision is happening for some reason. Any help is greatly appriciated!

    #2
    Set whatever object you want the line trace to hit to blockall in its collision. You can do this in c++ or if you have a blueprint class of the c class, you can do it in the blueprint editor.
    Make sure whatever object you want to collide with has a collision mesh or collision component. If your mesh doesnt have collision or you dont have a collision component the line trace will not hit.
    Put log statement directly after if (bHit) to ensure the line trace is working.

    Comment


      #3
      Originally posted by ViperG View Post
      Set whatever object you want the line trace to hit to blockall in its collision. You can do this in c++ or if you have a blueprint class of the c class, you can do it in the blueprint editor.
      Make sure whatever object you want to collide with has a collision mesh or collision component. If your mesh doesnt have collision or you dont have a collision component the line trace will not hit.
      Put log statement directly after if (bHit) to ensure the line trace is working.
      Hi there, thank you for the response. I've done all of these things and the line trace does work. The debug spams the console when i put it after the first if statement. it wont detect anything though. The static meshes in my scene have colliders that block everything too.

      Comment


        #4
        check if focused object is valid, if it is then get the actors name and print that to the log as well. I suspect its the other if statements after this have the issue.

        Comment


          #5
          Here's the code I'm using to check for interactive objects. COLLISION_INTERACTIVE is a trace channel I've set up, you can use Visibility or whatever else instead.
          So the differences - I'm using actor eye location, as actor position (which is its pivot point) is usually at the bottom of the actor, as well as ignoring myself in the trace.
          You should also check that the targeted actors block the trace channel you are testing against.

          Code:
          FVector EyeLocation;
          FRotator EyeRotation;
          GetActorEyesViewPoint(EyeLocation, EyeRotation);
          
          FVector TraceDirection = EyeRotation.Vector();
          FVector TraceEnd = EyeLocation + (TraceDirection * TargetTraceDistance);
          
          FCollisionQueryParams QueryParams;
          QueryParams.AddIgnoredActor(this);
          
          FHitResult Hit;
          GetWorld()->LineTraceSingleByChannel(Hit, EyeLocation, TraceEnd, COLLISION_INTERACTIVE, QueryParams);
          
          TargetActor = Hit.GetActor();

          Comment

          Working...
          X