Move to target, before starting Dialogue

Hi, i am working on making the Player move to the NPC before starting a Dialogue.

I ran into this answer from Brian;

It needs to be an IAction to function properly…
I make the PlayerConversant inherit the IAction interface
This means that StartDialogue will need to call ActionScheduler like fighter and Mover do, and will also need a Cancel() method to clear the target.
Then rather than immediately opening the dialogue, an Update method in PlayerConversant will move to the AIConversant, interacting when the player is in range.

So i implemented the IAction to the PlayerConversant, at first i had to click once,
then it would move in range, then click again to actually start the Dialogue.
I fixed that by storing the AIConversant and Dialogue in extra variables,
and as soon as IsInConversationRange() is true, it would call the StartDialogue()
again,with the 2 saved ones from when the AIConversant called StartDialogue.
It all seems to work well like this, but i think this is not how he meant it?

        public void Update()
        {
            if(currentConversant == null) { return; }

            if (!IsInConversationRange())
            {
                mover.MoveTo(currentConversant.transform.position, conversationRange);
            }
            else
            {
                mover.Cancel();

                if (savedConversant != null && savedDialogue != null)
                {
                    StartDialogue(savedConversant, savedDialogue);
                    savedConversant = null;
                    savedDialogue = null;
                }
            }
        }

        public void StartDialogue(AIConversant newConversant, Dialogue newDialogue)
        {
            actionScheduler.StartAction(this);
            savedConversant = newConversant;
            savedDialogue = newDialogue;

            currentConversant = newConversant;

            if(!IsInConversationRange()) { return; }

            currentDialogue = newDialogue;
            currentNode = currentDialogue.GetRootNode();
            TriggerEnterAction();
            onConversationUpdated();
        }

        public void Cancel()
        {
            mover.Cancel();
            Quit();
        }

        public bool IsInConversationRange()
        {
            return Vector3.Distance(transform.position, currentConversant.transform.position) < conversationRange;
        }
1 Like

@Brian_Trotter, could you help with this problem? (Given it is still relevant.)

Hi Nina, or Brian,

It is not needed per se, it all seems to work.

Also i learned i should always tag my questions by now!
Thanks!

This, or you could have tagged Brian in your post since you quoted him. (We probably have lots of Brians here.) :wink:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms