Page 1 of 1
How to set a distance for NPC barking in 2D?
Posted: Sat Jun 10, 2023 7:11 pm
by Eldritch_Horror
How would I best resitrict NPC barking to when the player is within a certain distance in a 2D game? I tried a variable set by a trigger, but it didn't work.
Re: How to set a distance for NPC barking in 2D?
Posted: Sat Jun 10, 2023 10:07 pm
by Tony Li
Hi,
1. Add a Circle Collider 2D to the NPC. Tick Is Trigger. Set the radius to the max distance at which the player can hear the bark.
2. Add a Range Trigger component to the NPC. Set Conditions > Accepted Tags to Player (assuming your player GameObject is tagged "Player".) Assign your bark-related component(s), such as Bark On Idle, to the Components list.
Re: How to set a distance for NPC barking in 2D?
Posted: Sun Jun 11, 2023 2:38 pm
by Eldritch_Horror
The bark is still active from the games start. The collider is also acting to start the dialogue/conversation with the character.
Re: How to set a distance for NPC barking in 2D?
Posted: Sun Jun 11, 2023 4:03 pm
by Tony Li
Hi,
Disabled the Bark On Idle component at design time by unticking the checkbox next to the Bark On Idle component's heading.
If your Dialogue System Trigger is set to OnTriggerEnter, that would explain why it's starting the conversation when you enter the trigger collider. Here are two ways to resolve it:
1. If you're using AC's interaction and a Third Party: Dialogue System Conversation action, you probably don't need to the Dialogue System Trigger at all. You can remove it in this case.
2. Or, if you need it to trigger OnTriggerEnter, create an empty child GameObject. Move the big range trigger collider and the Range Trigger component to the child GameObject.