Page 1 of 2
Making the UI follow the NPC
Posted: Mon Jan 04, 2021 10:10 pm
by Smugz
Hi, so I have almost everything working except for the UI. I'm using EmeraldAI and a world space camera for VR, when the NPC starts moving the dialogue box stays where I placed it (originally infront of the NPC), I was wondering how i'd get it to follow the NPC so when it's activated it's infront of the NPC no matter where the NPC has wandered. I tried placing it inside the NPC so that it was it's parent but then it just stopped appearing all together
Re: Making the UI follow the NPC
Posted: Mon Jan 04, 2021 10:38 pm
by Tony Li
Hi,
A world space canvas childed to the NPC is the way to go. If it's not visible, pause the game and check where it is. Maybe it needs to be higher or lower, or maybe the NPC's scale is causing the canvas to be scaled too small or too large.
Re: Making the UI follow the NPC
Posted: Tue Jan 05, 2021 10:50 am
by Smugz
--
Re: Making the UI follow the NPC
Posted: Tue Jan 05, 2021 10:51 am
by Smugz
Hi, so I got this working and it's lead me onto what is hopefully my final question. Using Emerald AI, is there a simple option in dialogue manager to make the NPC stop moving and face the player?
Re: Making the UI follow the NPC
Posted: Tue Jan 05, 2021 11:42 am
by Tony Li
Hi,
Set the Emerald AI's Temperament > Behavior to Passive and Wander Type to Stationary.
One way is to add a script that has OnConversationStart and OnConversationEnd methods to the AI. (See
Script Methods.) In OnConversationStart, use the Emerald AI API to set Behavior and Wander Type. In OnConversationEnd, set them back to their original values.
Another way to do it without scripting is to add two extra Dialogue System Triggers:
- Set one to OnConversationStart. Select Add Action > Run Lua Code. Use the integration's Lua Functions SetEmeraldBehavior and SetEmeraldWander. For example:
Code: Select all
SetEmeraldBehavior("go=MyGameObject", "passive");
SetEmeraldWander("go=MyGameObject", "stationary")
where MyGameObject is the name of the AI.
- Set the Dialogue System Trigger to OnConversationEnd. Use Run Lua Code to set the behavior and wander state back to their original values.
In your conversation's first node (the one after <START>), set the Sequence field to something like:
Code: Select all
LookAt(listener,speaker); {{default}})
This uses the LookAt sequencer command to make the speaker (the NPC) look at the listener (the player).
Re: Making the UI follow the NPC
Posted: Tue Jan 05, 2021 1:56 pm
by Smugz
In your conversation's first node (the one after <START>), set the Sequence field to something like:
CODE: SELECT ALL
LookAt(listener,speaker); {{default}})
This uses the LookAt sequencer command to make the speaker (the NPC) look at the listener (the player).
So I noticed you said "something like", so i've been trying different variations I could think of, and read through the Sequencer help stuff but still had no success. The Character stops moving now which is great, just refuses to look at the player.
Re: Making the UI follow the NPC
Posted: Tue Jan 05, 2021 2:46 pm
by Tony Li
I forgot that Emerald AI takes control of the GameObject's rotation. I don't remember the details of how it keeps control. You may need to dig into the code of EmeraldAISystem or ask on BHS's forum how to rotate an Emerald-controlled GameObject. Alternatively, you could try just temporarily disabling the EmeraldAISystem component during the conversation.
Re: Making the UI follow the NPC
Posted: Tue Jan 05, 2021 9:43 pm
by Tony Li
I did a little checking. If the Emerald AI is set to Stationary, then you
can rotate it.
Make sure the player is assigned to the Dialogue System Trigger's Actions > Start Conversation > Conversation Actor. Then set the first NPC node's Sequence to:
I changed up the command a little to make the speaker (NPC) rotate to the listener (player) gradually over a duration of 1 second. But the original command should work fine, too.
Re: Making the UI follow the NPC
Posted: Thu Jan 14, 2021 10:03 am
by Smugz
Sorry for the long reply I got caught up in some other stuff, so the rotating thing worked when I set the character to stationary, however when I try to run the lua code to change from Dynamic wandering to Stationary I get this error, not entirely sure why. (I did also try capitalising the S)
SetEmeraldWander("go=Stark", "stationary")' threw exception 'Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?'
Re: Making the UI follow the NPC
Posted: Thu Jan 14, 2021 10:33 am
by Tony Li
Hi,
Did you add an Emerald AI Lua component to your Dialogue Manager?
If so, check the spelling and capitalization of your Lua code.