How to condition barks based on player proximity

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
erasmo.rayon
Posts: 7
Joined: Thu Nov 28, 2019 2:40 pm

How to condition barks based on player proximity

Post by erasmo.rayon »

Hi there! I followed the video tutorial on how to use barks

My NPCs barks are running correctly but it's kinda weird that they start playing automatically regardless of what the player currently doing in the scene. I'm building a scene where your playable character can overhear NPC conversations (barks), but only when he's at a minimum distance.

Is it possible to condition the barks so that they only start playing when the player is in close proximity of the NPC? If so, how do you set this up?
User avatar
Tony Li
Posts: 22135
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to condition barks based on player proximity

Post by Tony Li »

Hi,

You can use a Trigger Event or Range Trigger with Bark On Idle.

1. Add a Bark On Idle component to the NPC. Disable it.

2. Add a trigger collider to the NPC or a child GameObject. Make sure it's on a layer that will register collisions with the player's layer. Size the collider to the maximum range at which the player can be and still hear the NPC bark.

3. Add a Trigger Event or Range Trigger to the same GameObject. Let's say you're using Trigger Event. Set the Tag Mask to the Player tag. Configure the OnTriggerEnter() event to enable the Bark On Idle component. Configure OnTriggerExit() to disable it.

Assign a conversation to the Bark On Idle component. You can set Conditions on the conversation nodes. For example, say you have a Dialogue System variable "Player_Is_Muddy" that you set true when the player falls in the mud. You can set up a conversation node like:
  • Dialogue Text: "Look at that person! So muddy!"
  • Conditions: Variable["Player_Is_Muddy"] == true
Post Reply