Page 1 of 1
2D conversation trigger
Posted: Thu Aug 05, 2021 5:30 pm
by howevertt322
Hi, I am trying to implement the way in 2D I can click on an NPC object to start a conversation when the player is within a certain radius around NPC. I just watched your quick start video, but I am still confused on how to do that, right now I am planning to add onTriggerEnter to enable the Dialogue System Trigger component, and disable this component when the player leaves, is that the right way to do that?
Re: 2D conversation trigger
Posted: Thu Aug 05, 2021 5:53 pm
by Tony Li
Hi,
First make sure you've ticked the Dialogue System Welcome Window's USE_PHYSICS2D checkbox.
Add a trigger collider and rigidbody2d to the NPC. Tick the collider's Is Trigger checkbox. Since you want conversations to work within a certain radius, use a Circle Collider 2D and set the radius. You can set the rigidbody2d to Kinematic so it affected by physics forces such as gravity.
Then add a collider and rigidbody2d to the player. You can set the rigidbody2d to Kinematic.
Make sure the player and NPC are on layers that will register physics collisions. (Check the matrix in Edit > Project Settings > Physics 2D.)
Once you've done the basic Unity physics setup above, you can set up the Dialogue System part:
On the NPC, add a Usable component and Dialogue System Trigger. On the Dialogue System Trigger, select Add Action > Start Conversation. Select the conversation you way to play.
On the player, add a Proximity Selector component and Selector Use Standard UI Elements component.
Then test it out. When the player enters the NPC's trigger collider radius, you should see a yellow selector message such as: "NPC / (spacebar to interact)". Press the space bar. It should start the conversation. You can also click the right mouse button since it's mapped to the input named "Fire2".
If you want to start conversations with left mouse click, change the Use Key to "mouse 0" or change the Use Button to "Fire1".
Re: 2D conversation trigger
Posted: Sat Aug 07, 2021 5:28 am
by howevertt322
Hi Tony,
Thank you for your reply, it works well and what if I want a further improvement. I want my character can have multiple interactions within the radius, like trade and talk(start the conversation). When I left click the NPC there will be a window pop up and several options button I can click, only the talk button will lead to the dialogue system, so my intuition is that I can set the button as the NPC object in the scene, or is there any other way I can bind the button to start conversation. I am sorry for any inconvenience.
Re: 2D conversation trigger
Posted: Sat Aug 07, 2021 8:14 am
by Tony Li
Hi,
You could configure the Talk button's OnClick() event to call the Dialogue System Trigger's OnUse method. You might want to think of a general-purpose way to do this so you can easily apply the same configuration to different NPCs.
Re: 2D conversation trigger
Posted: Sat Aug 07, 2021 11:33 am
by howevertt322
In this case, do I still need a selector or just use the button to call function
Re: 2D conversation trigger
Posted: Sat Aug 07, 2021 12:19 pm
by Tony Li
If you're handling the multiple interaction pop-up window without using a Selector, then you don't need a Selector to start the conversation. Just have your pop-up window call the Dialogue System Trigger's OnUse() method directly.