Page 1 of 1
Conversation On Trigger Enter issue.
Posted: Sat Jan 23, 2016 1:42 pm
by kilfeather94
I'm just having a problem in regards to starting a conversation upon entering an NPC's trigger. I have the script 'Set Component Enabled On Dialogue Event' so that the player's scripts which are used to control and move the player are disabled when a conversation starts. This works perfectly when I'm triggering a conversation through 'On Use'. But if I start a conversation through ' On Trigger Enter', when the player walks into the NPC's trigger, the player will keep walking forward, even though the player's scripts have been disabled, which I checked in the inspector on runtime. Has anyone else experienced this problem and if so, is there a solution?
Re: Conversation On Trigger Enter issue.
Posted: Sat Jan 23, 2016 2:20 pm
by Tony Li
Hi,
If you switch the trigger back to
On Use and trigger the conversation while running at full speed toward the NPC, do you get the same problem?
If so, perhaps you need to do something more than just disable the script, such as stopping root motion animation. If it's just stuck in the wrong animation state, you can add a
Set Animator State On Dialogue Event component to your player to transition to an idle state.
If it's more complicated than animation, you can add a custom script that has an
OnConversationStart method.
If neither of those suggestions help, please feel free to send an example to tony (at) pixelcrushers.com. I'll be happy to take a look.
Re: Conversation On Trigger Enter issue.
Posted: Sat Jan 23, 2016 4:30 pm
by kilfeather94
Yeah, when I switched back to 'On Use' and triggered the animation while running at full speed, the same issue happened. My 'idle' animation is inside a Blend Tree. The Blend Type is 2D freeform cartesian, with parameters 'Turn' and 'Forward'. It is in Idle when the 'Forward' parameter is at 0.
I'm not entirely sure how the 'Set Animator State on Dialogue Event' script works. For the 'On Start' part of this script, what should the state name be if I'm using a blend tree that has the idle animation inside it. And also, does 'cross fade duration' apply in this case?
Re: Conversation On Trigger Enter issue.
Posted: Sat Jan 23, 2016 4:51 pm
by Tony Li
The 'Set Animator State On Dialogue Event' component only switches states. It doesn't touch animator parameter values.
Would it be possible to add another Idle state for conversations that only plays the idle clip? Then you could configure the component like this:
(Cross Fade Duration is the time in second that it blends between the player's current state and new state.)
If not, you'll need to write a small script. Something like:
Code: Select all
using UnityEngine;
public class IdleOnConversationStart : MonoBehaviour {
public void OnConversationStart(Transform actor) {
GetComponent<Animator>().SetFloat("Forward", 0);
}
}
Re: Conversation On Trigger Enter issue.
Posted: Sat Jan 23, 2016 4:59 pm
by kilfeather94
Just tried the first option you suggested and added a separate Idle state and that worked
Thanks very much for the help and quick response.
Re: Conversation On Trigger Enter issue.
Posted: Sat Jan 23, 2016 5:00 pm
by Tony Li
Happy to help!