block a raycast from passing through objects

DeanMarquette

New member
The "Can See Object" from the movement pack passes through walls.

Is there anyway to detect the player only when he is really within sight?
 

Justin

Administrator
Staff member
My guess is that this is caused by one of the following:

1. The Can See Object task is not using the correct layers
2. The raycast is starting at the bottom of the character so it passes through the bottom of the wall before reaching the target. You can prevent this from happening by increasing the y offset value on the task.
 

Diggidy

Member
Having the same problem.
I tried adjusting the Y offset from 1, 1.8 and 5.
As for the layers, on the Object Layer Mask I have the character layer and the environment layer, Ignore Layer Mask is set to Ignore Raycast.
The NPCs still detect me through walls.

I have the Target Tag set to Player

I've also tried Object Layer Mask set to character and set to nothing.
 

Justin

Administrator
Staff member
I wouldn't use tags because tags perform more slowly compared to layers. Just to get started have you tried setting the target directly, similar to the demo scene?
 

Diggidy

Member
When using Nolan in my scene, it works. So im obviously missing a step. You asked if I set the target directly, but when I look at the Behavior tree the Target variable is always None. Where do I set the target?
 

Justin

Administrator
Staff member
To get started you can directly set the target within the Can See Object task.
 

Diggidy

Member
Is the Can See Object searching by the Character layer working as intended then? Meaning if I leave the tag blank and set the layer to Character is it suppose to see through walls and objects?
 

Justin

Administrator
Staff member
The Object Layer Mask will search for objects within the specified layer, whereas the Ignore Layer Mask will specify which layers you want to ignore. To get started you should only have the Ignore Raycast layer within the Ignore Layer Mask.
 

Diggidy

Member
I have tried this, just as the demo scene is setup but it still detects the Character through walls. Is that as intended?
 

Justin

Administrator
Staff member
It sounds like it is offset related then. If you can tell me how to reproduce it I can verify.
 

Diggidy

Member
I created a new character in the demo scene and it worked. After I did that, I noticed that the colliders around the joints were missing from the original character maybe this had something to do with it? The original character didn't create correctly?
 

Diggidy

Member
Its the ragdoll or lack there of. When the character doesnt have a ragdoll the NPCs can detect it through walls.

In the ThirdPersonShooterScene create a new character without the ragdoll. The hide behind a wall in the path of AgentNolan.
 

Justin

Administrator
Staff member
Ah.. I see what is going on. If you deselect "Use Target Bone" then it'll work correctly.

Within MovementUtility the Line of Sight check fails within WithinSight, and if it detects that the object doesn't have a collider then it will just check the object's active state. I need to rework this logic a bit. For now you can also just remove the following from MovementUtility:

Code:
 else if (GetComponentForType<Collider>(targetObject) == null && GetComponentForType<Collider2D>(targetObject) == null) {
                    // If the linecast doesn't hit anything then that the target object doesn't have a collider and there is nothing in the way
                    if (targetObject.gameObject.activeSelf)
                        return targetObject;
                }
 
Top