adding another test to the proximity selector (facing angle)

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Strook
Posts: 70
Joined: Fri Nov 08, 2019 10:51 am

adding another test to the proximity selector (facing angle)

Post by Strook »

Hello,

I want to use the proximity selector in my game to be able to interact with usables because its the one that make the most sense compared to the raycast selector !

However, i would like to add a small feature to the proximity selector :

I want to check if the player is in the trigger AND facing the usable to be able to use it;


I would be interested to know what is the easiest and cleaniest way to implement that ? I have the whole logic for the facing part (using a Dot Product between player forward and usable forward), but im not sure where to put it

I tried creating a new component that disable/enable the usable when the player is not facing, it works but not perfectly


thank you !!
Currently working on ->Squeakross: Home Squeak Home<- Using Dialogue System Save System and other features.
Previous game made with Dialogue system ->The Spirit and The mouse<-
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: adding another test to the proximity selector (facing angle)

Post by Tony Li »

Hi,

No need to write any code. Just change the collider that the Proximity Selector uses. For example, you could add a Box Collider trigger that's positioned just in front of the player.

However, if you also want the usable object (e.g., NPC) to be facing the player, you could add a script to the usable object. Hook into Usable.onSelect() and onDeselect() to know when the player has selected it. Then, in Update(), set the Usable component enabled or disabled based on whether they're facing or not:

Code: Select all

Usable usable;
bool isSelected;

void Awake()
{
    usable = GetComponent<Usable>();
    usable.events.onSelect.AddListener(() => { isSelected = true; });
    usable.events.onDeselect.AddListener(() => { isSelected = false; });
}

void Update()
{
    usable.enabled = !isSelected || IsFacingPlayer();
}
User avatar
Strook
Posts: 70
Joined: Fri Nov 08, 2019 10:51 am

Re: adding another test to the proximity selector (facing angle)

Post by Strook »

hello and thanks for the reply

the first options seems perfect to me, what is the best way to change the collider used by the proximity collider ? Can i just add a child object with a collider, and add the proximity collider to it, or do the proximity collider component has to be on the player object ?

EDIT : this is what i did and it seems to work fine, please let me now if there any other way, but it work fine ! Thanks a lot for the help
Currently working on ->Squeakross: Home Squeak Home<- Using Dialogue System Save System and other features.
Previous game made with Dialogue system ->The Spirit and The mouse<-
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: adding another test to the proximity selector (facing angle)

Post by Tony Li »

Hi,

A child object is fine. Make sure to assign the main player object to the Proximity Selector's Actor Transform field.
Post Reply