Make player character bark when hitting a trigger?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Scrumbo
Posts: 16
Joined: Fri Feb 02, 2024 4:14 pm

Make player character bark when hitting a trigger?

Post by Scrumbo »

Hey there! I feel like this might be a simple question, but I’ve tried a bunch of things and have hit a bit of a wall, and I was wondering if I could maybe get some help!

I’m making a game in Unity 3D that’s entirely controlled through voice commands. Seeing as your only input is a microphone and a single key to record/send the command, I was trying to use the dialogue system to set up barks for the PC to say little things when he enters a trigger/collider instead of a dialogue window. So, the flow looks something like this:

- the player sends the command (Walk to the painting)
- the PC starts moving towards the destination.
- when the player hits a trigger/collider the player will let out a little bark like “woah, I wonder how long it took to make this…” or something like that.

Is there a good way to do this? A lot of the guides I found were for games that are a bit more traditional and only used NPCs to bark, which is helpful but not quite what I’m looking for.

I also saw a bubble style dialogue UI that I think would maybe work, but Id prefer if the player didn't have to click on continue every time and could have the dialogue clear on its own, not sure if that's a better solution or not!

Excited to hear from you all!
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Make player character bark when hitting a trigger?

Post by Tony Li »

Hi,

Set the player GameObject's tag to Player.

Add a Dialogue System Trigger component to the GameObject that has the trigger collider. Set the Trigger dropdown to OnTriggerEnter. Click the "Add 'Player' Tag" button. Select Add Action > Bark. If you set Bark Source to Text, you can enter the text and optional sequencer command right on the Dialogue System Trigger. If you set the Bark Source to Conversation, you can specify a conversation and optionally a specific dialogue entry in the conversation.

To play audio with the bark when Bark Source is set to Text, put your audio file in a folder named Resources. Then set the Bark Text Sequence to:

Code: Select all

AudioWait(audioClip)
where audioClip is the name of the audio file (without file extension such as .wav).

To play audio when Bark Source is set to Conversation, it's the same as playing audio with any conversation's dialogue entry. Cutscene Sequence Tutorials 1-4 cover that.

If you want to show text over the player's head, you can add an instance of the Bubble Template Standard Bark UI prefab to the player.
Scrumbo
Posts: 16
Joined: Fri Feb 02, 2024 4:14 pm

Re: Make player character bark when hitting a trigger?

Post by Scrumbo »

Thanks for the speedy reply! I tried setting things up how you had said to, but nothing seems to happen when the player enters the collider. For reference, I was following the instructions to have the speech bubble appear over the character's head.

I dedicated a new scene to testing this so no outside influences mess with it beyond what's necessary for the voice command controller, and I'll attach some pictures of the inspector in case they help. Knowing me I'm missing something small haha.
BarkTest1.png
BarkTest1.png (327.06 KiB) Viewed 521 times
I attached the dialogue system trigger to the "GreenCubeDestination" object, since that's where I have the player set to stop moving at. From there, the PC does have the Player tag on it. The PC has a collider on it as well as an instance of the Bubble Template Standard Bark UI prefab.

Thanks again for your help so far! Let me know if a video would be of any help!
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Make player character bark when hitting a trigger?

Post by Tony Li »

Hi,

Are there any errors or warnings in the Console window?

You may see a yellow warning that the player doesn't have a bark UI. It looks like you've added a subtitle panel bubble UI, but I don't know if you added a bark UI.

Make sure the player has a collider. It might also need a rigidbody, which you can set to Kinematic if you're not using the physics system (e.g., add forces) to move the player.

Temporarily set the Dialogue Manager's Other Settings > Debug Level to Info. This will log a lot of info to the Console window. When the player enters the trigger, you should see something about the Dialogue System Trigger firing. If not, check the usual Unity things to make sure Unity registers collisions. (More info: Intro to collisions)
Scrumbo
Posts: 16
Joined: Fri Feb 02, 2024 4:14 pm

Re: Make player character bark when hitting a trigger?

Post by Scrumbo »

Thanks again for the reply! Only just now had the time to test this, and you were right on the money! The player didn't have a rigidbody! I knew it was something simple hahah! Thank you so much for your help, Loving this plugin!
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Make player character bark when hitting a trigger?

Post by Tony Li »

Thanks! Glad to help!
Post Reply