What exactly do Eyes look for when you tick Require Sight?

Announcements, support questions, and discussion for Love/Hate.
Post Reply
RAWilco
Posts: 3
Joined: Thu Apr 20, 2017 2:15 pm

What exactly do Eyes look for when you tick Require Sight?

Post by RAWilco »

So I was wondering what exactly are a faction member's eyes looking for when a deed is ticked as Requires Sight? I have a situation set up in which I am having trouble getting a faction member to witness a deed that is being performed upon them.

It is like this:
- The Player fires a bullet at the faction member.
- There's a script (or in this case, a Playmaker action) on the bullet that, upon impact with the faction member, reports an Attack deed from the Player to the faction member.
- The deed has an impact of -80, so when it is successfully reported, the faction member's affinity to the Player drops quite drastically.

All of this works perfectly if I set the Attack deed to NOT require sight, and to have an infinite reporting radius (set to 0).
But what I would like to do is set the radius to around 10, so that only faction members in the local area are able to witness the attack, and to have it so that if the Player were to attack the faction member while in hiding, then they would not be able to witness it.

I'm having a little trouble with this however and would like to ask a few questions :
- When performing a sight check, what exactly does a faction member's eyes look for? Is it the other faction member that is performing the deed, or would it be whatever object the script is placed on (so in my situation, would it be the Player or the bullet)?
- And when looking for their target, would I be correct in assuming that the eyes perform a raycast to the target's origin point (the Player's feet in my situation)? And if so, is it possible to offset this so that they might look for another part of the target (if they were to look for the Player's torso rather than their feet, then I imagine the sight check should prove to be more reliable)?
- Also, and this is not related to my current problem, but is it possible to have the eyes operate with a cone of vision rather than a circular radius? So if the Player were to perform a deed while another faction member is within reporting range but is looking in the opposite direction, they would not be able to witness the deed?

And just to point out, the Eyes object for my faction member is an empty game object that hovers just a little way above the faction member's head away from any colliders, so I can confirm that there is nothing blocking its line of sight.

I apologise for the wall of text, I just wanted to make sure I explained everything clearly. And very nice job on the asset by the way.
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: What exactly do Eyes look for when you tick Require Sight?

Post by Tony Li »

Hi!

Love/Hate first does a distance check from the witness to the actor (the Player in your case). If the distance is within the radius requirement, it runs a "Can See" check.

By default, the "Can See" check runs a raycast from the witness's Eyes to the actor's origin point. It's successful if the raycast hits the actor (which must have a FactionMember component) without being blocked by anything closer in the Sight Layer Mask. Note that Love/Hate can run 2D or 3D raycasts (default 3D). If you're using the Deed Reporter component, you can set the dimension (2D or 3D) on it.

The Faction Member component has a CanSee delegate. You can assign your own C# function to run the check differently -- for example to shift the raycast up 1 unit to the actor's torso; or to check in a cone; or to run multiple raycasts to knees, torso, and head; etc. If you'd like to do any of that and need a hand, let me know. I can whip up a script for you.
RAWilco
Posts: 3
Joined: Thu Apr 20, 2017 2:15 pm

Re: What exactly do Eyes look for when you tick Require Sight?

Post by RAWilco »

Hi Tony,

Thanks for the answers and the lightning-fast response.

I would appreciate your help with both of those modifications if that's okay with you (I always feel a little out of depth modifying other people's scripts, especially when they're as well written as the ones in your asset. I'd be frightened of cluttering them up).
I'm currently using Behavior Designer to manage the general vision and hearing senses of my NPCs, so if I could work out a way to synchronise the cone of vision I currently have set in my behaviour tree with the one used for deed witnessing in Love/Hate I will be more than happy. Just being able to edit the cone angle in the inspector should do the trick I think.
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: What exactly do Eyes look for when you tick Require Sight?

Post by Tony Li »

Love/Hate is designed so you don't have to modify any of its scripts. Instead, it provides delegates to which you can assign methods that exist in your own scripts. For example, your own script might have a line of code line this:

Code: Select all

GetComponent<FactionMember>().CanSee = MyCustomRaycastFunction;
The FactionMember will then use your script's MyCustomRaycastFunction instead of its own internal vision check.

That's exactly what this package does:

LoveHate_CanSeeAdvanced_2017-04-20.unitypackage

After importing the package, you can add a CanSeeAdvanced component to your NPC. I cannibalized the code from an unpublished sensory perception system that adds three fields of view (FOVs) by default. If you only want one FOV, just delete the other two in the inspector. You can also specify extra height offsets to check, such as 1.0 for the actor's torso and 1.7 for the actor's head.

When the NPC is selected, the Scene view will show the FOVs. During play, it will also show the result of the last vision check:

Image

I'll include this in the next release of Love/Hate, too.

One last note: Make sure the player is actually detectable with a raycast. The screenshot above is from the Dialogue System. The default Player prefab in the Dialogue System only has a CharacterController, not a rigidbody or collider, and its layer is set to Ignore Raycast. So the first time I tested CanSeeAdvanced the raycast passed straight through the Player without detecting it.
RAWilco
Posts: 3
Joined: Thu Apr 20, 2017 2:15 pm

Re: What exactly do Eyes look for when you tick Require Sight?

Post by RAWilco »

Fantastic!

That works perfectly, thank you very muchly.

Oh and it turns out that there was something blocking the Love/Hate eyes' line of sight after all. It was free from any obstacles on the NPC, but I had forgotten about a couple of other game objects with Colliders I had placed on my Player, that were essentially acting like little invisible walls and were blocking all incoming raycasts. So yeah, that was my fault.

Thanks again, I really appreciate all the help.
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: What exactly do Eyes look for when you tick Require Sight?

Post by Tony Li »

Glad to help!
Post Reply