Page 1 of 1

Custom "Eyes" not involving raycasts

Posted: Wed Jul 27, 2016 5:01 pm
by Nosteme
Hello. I'm really digging Love/Hate so far. It's incredibly detailed and obviously had a lot of love poured into it :)

I'm hoping to utilize it as much as possible for my project. However, I'm having a bit of trouble with NPCs witnessing deeds. My project is set up similar to a traditional text adventure game where the idea of a room is more abstract than an actual physical space you can see in the Unity editor. Because of this, my NPCs don't necessarily have coordinates or take up a space, and thus getting them to actually witness deeds has been a bit difficult.

I considered making a secondary version of the FactionMember class with a differently functioning DefaultCanSee method, but the way everything in your code is all tied together neatly makes me think this might not be the best way to do this.

Do you have any suggestions or ideas for how to best override the deed witnessing system (and others associated with/relying on visual witnessing) such that it can work within my game?

Thanks!

EDIT: Nevermind, I found the CanSeeDelegate in FactionMember! Now I just need to better understand how the DefaultCanSee functions.
Hmm... I'm noticing the delegate requires a dimension enum. Since I'm using neither 2D nor 3D, what should I do about this? Should I just add "Neither" to the enum options and use that, completely ignoring the use of the dimension in my method?

Re: Custom "Eyes" not involving raycasts

Posted: Wed Jul 27, 2016 7:50 pm
by Tony Li
Hi,

Thanks for using Love/Hate!

You could add another enum value, but personally I'd leave them they way the are and just ignore the Dimension value. This way you won't lose your custom enum value if you update Love/Hate to a newer version. In general, Love/Hate is designed so you shouldn't have to modify any of the code directly. You can set the delegate in a new script. For example, you could add a script like this to your faction member GameObject:

RoomVision.cs:

Code: Select all

using UnityEngine;
using PixelCrushers.LoveHate;

[RequireComponent(typeof(FactionMember))]
public class RoomVision : MonoBehaviour
{
    void Start()
    {
        GetComponent<FactionMember>().CanSee = CanSeeInRoom;
    }
    
    bool CanSeeInRoom(FactionMember actor, Dimension dimension)
    {
        return IsActorInMyRoom(actor);
    }
}
You'd need to define the function IsActorInMyRoom() of course, but you can see that the delegate just ignores dimension.

Similarly, if you want to use Greeting Triggers, you can make a new subclass of AbstractGreetingTrigger:

RoomGreetingTrigger.cs

Code: Select all

using UnityEngine;
using PixelCrushers.LoveHate;

public class RoomGreetingTrigger : AbstractGreetingTrigger
{
    // Assumes CharacterEnteredRoom is called whenever a character enters this room.
    public void CharacterEnteredRoom(GameObject character)
    {
        HandleOnTriggerEnter(character);
    }
}
This also applies to Gossip Triggers, which are designed the same way.

Re: Custom "Eyes" not involving raycasts

Posted: Wed Jul 27, 2016 8:01 pm
by Nosteme
Perfect! That's exactly what I needed to know! Thank you!

Re: Custom "Eyes" not involving raycasts

Posted: Wed Jul 27, 2016 9:48 pm
by Tony Li
Happy to help!