OnTriggerEnter combined with Button Press

Announcements, support questions, and discussion for the Dialogue System.
OneManOnMars
Posts: 105
Joined: Tue Apr 05, 2016 9:37 am

OnTriggerEnter combined with Button Press

Post by OneManOnMars »

Hi,
I am very happy with the Dialogue System so far altough its fairly complex. What I would like to do is to activate a conversation only if the player is in the trigger area and pressing a specific button.
How would I achieve that?

I went trough a lot of the documentation an the tutorials but could not find it.

Many thanks for the support.
OneManOnMars
Posts: 105
Joined: Tue Apr 05, 2016 9:37 am

Re: OnTriggerEnter combined with Button Press

Post by OneManOnMars »

Ok, in the mean time I have found out that I have to use a proximity selector on the player and a usable on the npc.
But it doesn't work. :?
I checked to have the right layer.
Do I have to assigne a 2D Collider to the same gameobject as the proximity selector? yes.. it seems so!

I figured it out by now but I keep writing for the next guy that can't figure it out imediatly :D

Do I need a Rigidbody 2D on the same gamobject as the proximtiy selector? Yes, as far as I know.

So as you can see, I somehow could figure it our by myself - but I will have more questions in the future.
But as it seems your Dialoge System can do everything I need and much more. So I will send some money into your direction.

By the way providing a evaluation version is awesome! Thanks a lot!
User avatar
Tony Li
Posts: 21081
Joined: Thu Jul 18, 2013 1:27 pm

Re: OnTriggerEnter combined with Button Press

Post by Tony Li »

Hi,

Thanks! I'm glad you're enjoying using the Dialogue System!

Thanks for posting your solution to help future readers. Proximity Selector and the trigger components such as Conversation Trigger use Unity's standard physics trigger features. As long as it's set up to work in Unity, it'll work in the Dialogue System.
Xpyke
Posts: 13
Joined: Sun May 22, 2016 11:29 am

Re: OnTriggerEnter combined with Button Press

Post by Xpyke »

Hi, I'm having the same problem but cannot make it work the same way, I checked the documentation and the video tutorials to no avail, so here's the problem:

I have a 2D rpg, the like of chrono trigger, I have a player object with a custom controller script, a circle collider 2D, and a rigidbody2D all made by me and working with the other objects, so I used the player wizard and put a proximity selector in the player.

For the NPC I put it in the same layers as the player, and the NPC wizard installed 3 components in the object, they are Conversation Trigger (marked on use), an Usable script, and a Character Controller.

But when I approach the npc nothing happens, I press space (the default button) and the conversation does not start, I even redone everything in another project and the problem persists, what am I doing wrong?
User avatar
Tony Li
Posts: 21081
Joined: Thu Jul 18, 2013 1:27 pm

Re: OnTriggerEnter combined with Button Press

Post by Tony Li »

Hi,

Proximity Selector relies on Unity to register OnTriggerEnter2D events. Inspect your NPC and add a 2D collider with Is Trigger ticked. Here's an example scene:

ProximitySelector2DExample_2016-05-22.unitypackage

The example scene uses Unity's Standard Assets > 2D package, so you may need to import it to play the scene.

It also uses this script (ReportTriggerEnter.cs) to let you know when the player has entered the NPC's trigger area:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ReportTriggerEnter : MonoBehaviour
{
    void OnTriggerEnter2D(Collider2D other)
    {
        DialogueManager.ShowAlert(other.name + " entered trigger area of " + name);
    }

    void OnTriggerExit2D(Collider2D other)
    {
        DialogueManager.ShowAlert(other.name + " exited trigger area of " + name);
    }
}
You can add the script to your own NPC to help debug what's going on.
Xpyke
Posts: 13
Joined: Sun May 22, 2016 11:29 am

Re: OnTriggerEnter combined with Button Press

Post by Xpyke »

Tony Li wrote:Hi,

Proximity Selector relies on Unity to register OnTriggerEnter2D events. Inspect your NPC and add a 2D collider with Is Trigger ticked. Here's an example scene:

ProximitySelector2DExample_2016-05-22.unitypackage

The example scene uses Unity's Standard Assets > 2D package, so you may need to import it to play the scene.

It also uses this script (ReportTriggerEnter.cs) to let you know when the player has entered the NPC's trigger area:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ReportTriggerEnter : MonoBehaviour
{
    void OnTriggerEnter2D(Collider2D other)
    {
        DialogueManager.ShowAlert(other.name + " entered trigger area of " + name);
    }

    void OnTriggerExit2D(Collider2D other)
    {
        DialogueManager.ShowAlert(other.name + " exited trigger area of " + name);
    }
} 
You can add the script to your own NPC to help debug what's going on.
That was exactly the problem, thanks for the help, it's working now, but let me ask you something unrelated, when setting up the dialogue manager, I can choose to automatically pass the subtitles or force the player to press the continue button, but using the default UI there's no continue button, is there a default way to ask for the next line in the conversation? And can I choose the options from the response menu using the keyboard or only the mouse? Again thanks for the amazing support.
User avatar
Tony Li
Posts: 21081
Joined: Thu Jul 18, 2013 1:27 pm

Re: OnTriggerEnter combined with Button Press

Post by Tony Li »

Hi,
Xpyke wrote:That was exactly the problem, thanks for the help, it's working now, but let me ask you something unrelated, when setting up the dialogue manager, I can choose to automatically pass the subtitles or force the player to press the continue button, but using the default UI there's no continue button, is there a default way to ask for the next line in the conversation?
The default UI is very bare-bones, as you've seen. It should really offer a continue button, though. I'll add that in the next version.

The default UI also uses legacy Unity GUI. I recommend using the new Unity UI instead, since it's more efficient and flexible. Two easy ways to do this are:

1. Remove your old Dialogue Manager. Then go into the Dialogue System/Prefabs folder and drag the Dialogue Manager prefab into your scene/hierarchy. Remember to assign your dialogue database to the Dialogue Manager.

2. Or, to keep your existing Dialogue Manager, go into Dialogue System/Prefabs/Unity UI Prefabs/Generic and drag Generic Bundled UI onto the Dialogue Manager in your Hierarchy so Generic Bundled UI becomes a child GameObject of Dialogue Manager.

The Unity UI prefabs all support continue buttons.
Xpyke wrote:And can I choose the options from the response menu using the keyboard or only the mouse? Again thanks for the amazing support.
Yes. If you're using Unity UI, see Unity UI Keyboard and Gamepad Navigation in the manual for details. In brief: just tick Auto Focus on your Unity UI Dialogue UI component.

If you're using legacy Unity GUI, see Legacy Unity GUI Keyboard and Gamepad Navigation instead.
User avatar
supadupa64
Posts: 200
Joined: Sun Mar 06, 2016 9:40 pm
Contact:

Re: OnTriggerEnter combined with Button Press

Post by supadupa64 »

OneManOnMars wrote:Hi,
What I would like to do is to activate a conversation only if the player is in the trigger area and pressing a specific button.
So... out of curiosity, why would you need this? Does the player somehow activate the conversation from a far distance accidentally? From first glance I would just set the interaction distance to the desired amount without using proximity, but maybe I'm missing something here.
User avatar
Tony Li
Posts: 21081
Joined: Thu Jul 18, 2013 1:27 pm

Re: OnTriggerEnter combined with Button Press

Post by Tony Li »

supadupa64 wrote:So... out of curiosity, why would you need this? Does the player somehow activate the conversation from a far distance accidentally? From first glance I would just set the interaction distance to the desired amount without using proximity, but maybe I'm missing something here.
That's a good question. Here's my reasoning: In a lot of games (especially 2D console games), a common way to start conversations is by walking up to an NPC and pressing an action button. The ProximitySelector is designed to work like that.

In a 3D first-person or third-person over the shoulder game, it's easy to point the camera at an NPC to select it using the Selector component with the Select At position set to Center of Screen. But in a 2D game the player doesn't have that kind of control over the camera.

Another common way to start conversations in 2D games is to click on the NPC with the mouse; in this case you could use Selector and set the Select At position to Mouse Cursor. But if you're playing with a gamepad, you don't have a mouse cursor, so the standard solution is to use ProximitySelector.
Xpyke
Posts: 13
Joined: Sun May 22, 2016 11:29 am

Re: OnTriggerEnter combined with Button Press

Post by Xpyke »

Tony Li wrote:
supadupa64 wrote:So... out of curiosity, why would you need this? Does the player somehow activate the conversation from a far distance accidentally? From first glance I would just set the interaction distance to the desired amount without using proximity, but maybe I'm missing something here.
That's a good question. Here's my reasoning: In a lot of games (especially 2D console games), a common way to start conversations is by walking up to an NPC and pressing an action button. The ProximitySelector is designed to work like that.

In a 3D first-person or third-person over the shoulder game, it's easy to point the camera at an NPC to select it using the Selector component with the Select At position set to Center of Screen. But in a 2D game the player doesn't have that kind of control over the camera.

Another common way to start conversations in 2D games is to click on the NPC with the mouse; in this case you could use Selector and set the Select At position to Mouse Cursor. But if you're playing with a gamepad, you don't have a mouse cursor, so the standard solution is to use ProximitySelector.
That's exactly the reasoning, and I forgot to come here to say thanks, but let me ask you one more thing if you don't mind, is there an easy way for me to interact with objects, for example: When the player interacts with the TV he will say: Nice TV!

I can achieve this by creating conversations with just one line of speech, but is there a way to achieve player commentaries easier than this?
Post Reply