Page 1 of 2

Coversation Starts on Trigger

Posted: Sun Jun 05, 2016 12:38 am
by field2012
Hi Tony,

I read through the ontriggerenter documentation, everything seems to be fine to a point, then it stops working correctly. The thing I want to achive is, when player comes close to a castle gate, the guard initiates a conversation, simple as that. After conversation is finished, I want guard to have a normal standard conversation on use, like Hell there.. bye..etc

There are multiple issues I am facing such as:
- When a conversationn is Trigger as Player collides with the guard collider, it also shows the "Talk" button, which initiates dialogue. I though on trigger enter, player shouldn't get this option as the conversation is already started.

- The second issue is when conversation is finished, and then I click on Talk button, all the UI disappears.


Any help would be appreciated.

Re: Coversation Starts on Trigger

Posted: Sun Jun 05, 2016 1:18 am
by field2012
I found a solution to this by doing the following:

Created two game objects with conversations such as:

GameObjectOne:

SphereCollider - 7 m radius
Dialogue System Trigger Script used with Trigger option set to On Trigger Enter
Ticked Only Once
Condition Set Tag to Player

GameObjectTwo:
SphereCollider - 2 m radius
Conversation Trigger Script Used with Trigger set to On Use
Condition Set Tag to Player

So with the above setting I achieved what I wanted, not sure if this is a correct way, but seems to be working and will have to test it with a saved game.

Re: Coversation Starts on Trigger

Posted: Sun Jun 05, 2016 11:45 am
by Tony Li
Hi,

That will work unless in your game the player can leave and re-enter the scene -- including saving and loading games. The "Only Once" checkbox only works in the current instance of the scene. If you reload the scene, the trigger will be reset.

Here's another way:

1. Define a Dialogue System variable called something like "TalkedToGuard". Set its Type to Boolean and its Value to False.

2. Add a Persistent Active Data component to the guard. Set the Target to GameObjectOne. Set the Condition > Lua Conditions to:

Code: Select all

Variable["TalkedToGuard"] == false
3. Add another Persistent Active Data component to the guard. Set the Target to GameObjectTwo. Set the Condition > Lua Conditions to:

Code: Select all

Variable["TalkedToGuard"] == true
4. In the "On Trigger Enter" conversation, choose an appropriate dialogue entry node and:
  • Set the Script field to:

    Code: Select all

    Variable["TalkedToGuard"] = true
  • Set the Sequence field to:

    Code: Select all

    SetActive(GameObjectOne,false);
    SetActive(GameObjectTwo,true)
5. The Usable component should be on GameObjectTwo, but you can point the Conversation Trigger's Conversant field to the main guard GameObject.

If the player can move and target things during conversations and you don't want this to happen, please see How To Set Up the Player.

Re: Coversation Starts on Trigger

Posted: Mon Jun 06, 2016 5:10 am
by field2012
Hi Tony,

Ya there is a problem with the method I am using.

I tried following the method you described, but got confused with the second game object. Made few assumptions, but didn't get it to work.


Would it be possible to get a project with the above scenario?


P.S ya controls seems to be active on trigger enter, but it is disabled on use. The documentation doesn't talk about how to disable it ontriggerenter.
Cheers

Re: Coversation Starts on Trigger

Posted: Mon Jun 06, 2016 11:01 am
by Tony Li
Hi,

I'm out of the office at the moment, but I'll post a project as soon as I get back!

Re: Coversation Starts on Trigger

Posted: Mon Jun 06, 2016 8:57 pm
by Tony Li
Here's an example scene:

MultipleConversationTriggers_2016-06-06.unitypackage

The scene imports into "Dialogue System Examples/Multiple Conversation Triggers".

The dialogue database has two conversations:
  • First Conversation: Only runs the first time that the player enters Private Hart's trigger collider. Sets a variable "Talked_To_Hart" true and activates/deactivates the child GameObjects described below.
  • Second Conversation: Runs whenever Private Hart is "used," which only becomes an option after running First Conversation.
The NPC in the scene is Private Hart. He has two child GameObjects:
  • Hart_Trigger_One: Has a trigger collider and a Conversation Trigger set to OnTriggerEnter that runs "First Conversation".
  • Hart_Trigger_Two: Has a collider, a Usable component, and a Conversation Trigger set to OnUse that runs "Second Conversation". This child GameObject starts inactive.
Private Hart's main GameObject has a Persistent Active Data component that's used to reapply game states when loading games. When loading a game, it checks the value of the variable Talked_To_Hart. If the variable is true, it deactivates Hart_Trigger_One and activates Hart_Trigger_Two.

When you play the scene, you should see that you can't target Private Hart to "use" him. But you can run into his trigger collider to start "First Conversation". After running this conversation, you'll be able to "use" him to run "Second Conversation".

If you save your game after running "First Conversation", and then stop, play, and reload your game, you should see that the Hart_Trigger_Two child GameObject is active.

Re: Coversation Starts on Trigger

Posted: Tue Jun 07, 2016 7:08 am
by field2012
Thanks for the project. Will check it.

Re: Coversation Starts on Trigger

Posted: Wed Jun 08, 2016 9:09 am
by field2012
I followed the example and corrected few things in my project. Now everything is working fine, except that I have a User Interface (ie health bars, pad, camera etc) overlaps the dialogue box. The user interface is a prefab and gets loaded when game starts, so there is no way for me to add that to "Set Enabled On Dialogue Event" script to disable them. I think I will need a custom script for this or if you know of an alternative way, which would be good.

Thanks for the help.

Cheers

Re: Coversation Starts on Trigger

Posted: Wed Jun 08, 2016 9:29 am
by Tony Li
When you load the prefab, can you make it a child of an existing, empty GameObject in the scene? If so, then you can use Set Active On Dialogue Event to deactivate this GameObject during conversations.

Otherwise you could give the player or Dialogue Manager a custom script similar to this:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class DisableUIDuringConversation : MonoBehaviour {

    private GameObject ui = null;

    void OnConversationStart(Transform actor) {
        SetUI(false);
    }
    
    void OnConversationEnd(Transform actor) {
        SetUI(true);
    }
    
    void SetUI(bool value) {
        if (ui == null) ui = GameObject.Find("My GUI GameObject Name");
        if (ui == null) {
            Debug.LogWarning("Can't find UI to deactivate it.");
        } else {
            ui.SetActive(value);
        }
    }
} 

Re: Coversation Starts on Trigger

Posted: Thu Jun 09, 2016 7:41 am
by field2012
Thanks for the script, it worked, but I have encountered another problem. The player used to stop before, but now it continuously running in a forward direction when the dialogue is triggered.

Figured it out... Thanks