Stop raycast from going through wall

Hi, so I’m trying to make a system where when the player is looking at the skeletons, they freeze in place and when the player looks away, they start moving again. I have everything about their movement working. Just the logic behind what the player sees is kinda finicky. At this point, I’m using a multi-line box trace to check if they are in view. I got them to stop moving, but I’m unsure how to check when they aren’t being hit by the line trace. And the other issue I’m having is the line trace is going through walls. Any ideas on how to solve any of these problems would be greatly appreciated!

Hey @Zapking9224!

A few questions and a possible solution to get things started:

  • Is there a reason you are using a Multi Line Trace specifically instead of a single line trace?
  • Have you tried using a Multi Line Trace by Channel? (by object will go through any object regardless of overlap or blocking. This could potentially solve your problem if you follow the steps in the linked documentation.)
  • Additionally, is the collision for your walls set to block all?

Any additional specifics you provide will go a long way in solving your problem!

Hey @Quetzalcodename!
Here’s a screenshot showing what’s happening here. I’m right now using the multi line trace by channel and the lines are still going through the walls. The reason I’m using the multi line trace is because there are multiple skeletons running around that the player will see. Maybe I’m not understanding the point of using the multi line trace but from what I’m understanding, it’s so it can detect more than one object.

Multitrace is for penetrating overlapping obstacles.

Consider Pawn Sensing instead.

  • in the Skelly:

  • in the Player:

Can be improved, surely.

For something more elaborate and with more control, dot product:

Have a look at the thread. Some unorthodox (just messing around with stuff) methods there.

Hey @Everynone!
I got it working to have the skeleton stop when the player is looking at them. However, I’m not sure how to get them to start moving again when the player looks away. I’m using a behavior tree and it runs the move to player branch when the boolean is false and goes to the freeze branch when the boolean is true.

Hey @Everynone!
So I came up with a solution to unfreezing the skeleton, but it only works on one at a time. It freezes both of them when I look at either one of them, but when I look away from both of them, it only unfreezes one of them and the other stays frozen. The only way to unfreeze the other one is to make sure it’s the most recent one seen which is kinda hard to pull off but it is possible. I’m not sure why it isn’t individually working for both of them.