CanSeeObject - Why it never works as expected?

I think I have a problem with this task in every single case scenario and more specifically with Offset's Y and Target Offset's Y, these two vectors determine if the task will work correctly or not, but they vary depending on the current NPC and target.

I can have my target be in line of sight (according to the debug drawer), but the CanSeeObject task will return failure if I dont set the correct offset's Y, so some NPC's work great with 0 then I change my target it requires both of these values to be set to 1, I just can't wrap my head around this why its needed and whats the logic behind it.

Why the CanSeeObject works normally if the NPC is a human archer, the target is player and both of the Offsets are set to 0,1,0 but then I change the target to a cube and it won't work unless I set both of them to 0,0,0 or the offset 0,1,0 and the target offset to 0,0,0, can this thing just use the same vector across ALL enemies and ALL npcs? I haven't updated BD in awhile so if something in this script has been changed I will download the new version.

Let's demonstrate it:
Offset is 0,0,0
Target Offset is 0,0,0
Put the cube in the air

As you can see the debugger draws the angle from the feet of the model (I think the pivot is actually at her stomach not feet but lets assume its right and its casting from the feet) and the cube is above the ground so it shouldn't see it right? Wrong it detects it perfectly fine

above.png


Now lets change it like this
Offset 0,1,0
Target Offset 0,1,0
And put the cube back on the ground

middle.png

The yellow angle drawn by the gizmos goes right in the middle of the cube, it seems like it should work right? Well it doesn't work my NPC cannot see the cube in that case.
 
Last edited:
You should download the latest version - a new debug variable has been added which gives you a color coded line indicating the status.


The offset position is based on the object's pivot position. If you use a smaller y value then that should work with both a cube and character.
 
Not necessarily - I recommend getting the latest and then you can visually see where the raycast is being set from. Offset is relative to the agent's pivot position while target offset is relative to the target's pivot position.
 
Okay I think I found how to setup this but there is a problem, it still requires different values on the Target Offset vector dpeending on the current target - cube, NPC, flying monsters etc. Maybe I should have a script on the target called CanSeeObjectRayCastOffset and set the Vector there different depending on what the target model is and the CanSeeObject task can read that value from the current game object Im trying to hit.
 
I get this problem when I get close to the NPC. Im wondering if there is a way to see the target no matter how close you are to it.

I think this check is not allowing that to happen currently when I get too close --> if (direction.magnitude < viewDistance && angle < fieldOfViewAngle * 0.5f)



ccccc.png
 
Last edited:
The red line does indicate that it's a field of view issue. The angle is determined with:

Code:
                angle = Vector3.Angle(direction, transform.forward);

So the offset is considered within this angle. If you increase the angle it should work better.
 
Top