Coversation Starts on Trigger
Coversation Starts on Trigger
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.
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.
Last edited by field2012 on Sun Jun 05, 2016 1:30 am, edited 1 time in total.
Re: Coversation Starts on Trigger
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.
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
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:
3. Add another Persistent Active Data component to the guard. Set the Target to GameObjectTwo. Set the Condition > Lua Conditions to:
4. In the "On Trigger Enter" conversation, choose an appropriate dialogue entry node and:
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.
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
Code: Select all
Variable["TalkedToGuard"] == true
- 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)
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
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
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
Hi,
I'm out of the office at the moment, but I'll post a project as soon as I get back!
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
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:
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.
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.
- 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.
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
Thanks for the project. Will check it.
Re: Coversation Starts on Trigger
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
Thanks for the help.
Cheers
Re: Coversation Starts on Trigger
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:
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
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
Figured it out... Thanks
Last edited by field2012 on Fri Jun 10, 2016 10:22 am, edited 1 time in total.