How to set a distance for NPC barking in 2D?
-
- Posts: 28
- Joined: Sun May 28, 2023 8:30 pm
How to set a distance for NPC barking in 2D?
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?
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.
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.
-
- Posts: 28
- Joined: Sun May 28, 2023 8:30 pm
Re: How to set a distance for NPC barking in 2D?
The bark is still active from the games start. The collider is also acting to start the dialogue/conversation with the character.
- Attachments
-
- Clipboard01.png (542.77 KiB) Viewed 209 times
Re: How to set a distance for NPC barking in 2D?
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.
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.