Dialogue only showing up within a certain distance?

I’m assuming there is a way, and it’s either too late in the day for me to think of it, but is there a way, much like moving to a pick up to actually pick up the pick up, to move towards an AI conversant instead of being able to click on them from across the map?

Make your PlayerConversant an IAction, and use a target like Fighter does.

AIConversant targetConversant;

        public void StartDialogueAction(Dialogue dialogue, AIConversant speaker)
        {
            Debug.Log($"StartDialogueAction {speaker}/{dialogue}");
            if (currentConversant != null && currentConversant == speaker) return;
            if (currentDialogue != null) QuitDialogue();
            if (dialogue == null)
            {
                return;
            }

            GetComponent<ActionScheduler>().StartAction(this);
            targetConversant = speaker;
            currentDialogue = dialogue;
        }

        private void Update()
        {
            if (targetConversant)
            {
                if (Vector3.Distance(targetConversant.transform.position, transform.position) > 3)
                {
                    GetComponent<Mover>().MoveTo(targetConversant.transform.position);
                }
                else
                {
                    GetComponent<Mover>().Cancel();
                    StartDialogue();
                }
            }
        }

        private void StartDialogue()
        {
            currentConversant = targetConversant;
            targetConversant = null;
            var nodes = FilterOnCondition(currentDialogue.GetRootNodes()).ToArray();
            SetCurrentNode(nodes[Random.Range(0, nodes.Length)]);
            OnCurrentDialogueChanged?.Invoke();
        }

Then in AIConversant.HandleRayCast(), you’ll call the PlayerConversant.StartDialogueAction(dialogue, speaker);

2 Likes

what is FilterOnCondition? I’m getting an error here, and it wants me to generate a method

Oops, that’s from my personal project. I have things set up so you can have multiple root nodes (complete with random greetings, and a greeting based on a condition, rather than the same greeting with the 2nd sentence).
Replace that with SetCurrentNode(currentDialogue.GetRootNode()); // or however your code gets the root node

1 Like

IDK if I’m just missing it, but I also don’t have a SetCurrentNode. Would I just run currentDialogue.GetRootNode()?

I think I followed the naming convention from the course (I finished the dialogue portion, just started on the Quest portion). I’m just unsure if I’m missing anything here. haha.

Replace that with

currentNode = currentDialogue.GetRootNode();
1 Like

Ah, that FilterOnCondition method will make a lot more sense at the end of the Quest portion.

Okay, just to see if I’m understanding you correctly.

I’m replacing both lines:

var nodes = SetCurrentNode(currentDialogue.GetRootNode());
SetCurrentNode(nodes[UnityEngine.Random.Range(0, nodes.Length)]);

with

currentNode = currentDialogue.GetRootNode();

or just one of those lines with it?

Do I put anything in the generated Cancel function that came in with IAction?

I figured it out, i went ahead and tested replacing both lines with the currentnode=currentDialogue.GetRootNode(); and that did the trick.

I did, strangely, run into a weird bug with aggro when I tested out using this to get all of the guards to aggro me after I run the “attack” trigger.

If I run through all of the enemies while they’re “passive” then come back and trigger the attack trigger (which causes the passive enemy with the dialogue on it to aggro shout to everyone" everyone in the level swarms the player. Does this get fixed throughout the course at some point?

1 Like

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

Privacy & Terms