Download

How to stop NPC AI from walking around when interacting with it (using Ai behaviour tree)

Hello there!
I rarely post on forums because I always feel guilty of stealing people’s time but in this case i’m way over my head on this topic :s
I’ve been following some tutorials on youtube from Ryan Laley (specifically the dialogue on and the begining of the ai ones) and trying to piece stuff together to fit my needs. His Ai tuts are design to make an ennemy npc, where I just want a simple interactable villager NPC or something as such.

Here is what i seem to understand. I have an NPC with a small trigger box attached to him. When I interact with him pressing E and being in its trigger zone, it starts a task to create my dialogue widget and stop the player and player camera from moving and switch to the npc camera for nice framing.
When the dialogue lines runs out, I get the control and camera back to my player. (Not shown here is the line index graph to tell me where am I in the dialogue)

Here is what’s in my dialogue create. I don’t know if it’s relevant but i’d rather be thorough just in case


I’ve been wondering initially if I should use the StopMovement or StopMovementImmediately or have a AiMoveTo referenced to itself withing this graph, so the npc would stop when the DialogueCreate is being executed. But Since i’m using the AI system to make it walk around it doesn’t seem to work.

Here is what I was thinking of for the AI graph


Running the bottom right sequence works fine on its own. So i was thinking of Checking of the Npc is being interacted with. If so, then stop, if not then run the bottom right sequence.
On my sequences IsBeingTalkedTo, I use a boolean varialble IsAiTalking from the blackboard So I though it it’s yes run the left tree if it’s not run the right tree. I was hoping to set this boolean value within my Task_IsTalking.
Here’s whats in the two tasks

and the other


this one feels pretty hacked but I had no idea of to get the StopMovement from here.

So in the end I have no idea if my whole thiking process is off, If I messed up the behaviour tree branching or if it’s something simple. Like I said I’m a bit out of my range there :s I’m an Env artist and my own brain is probably as badly wirred for tech stuffs as this Ai graph :s

Anyhow if anyone have a suggestion you’d have my eternal gratitude <3

Funny thing is I’m about to tackle this subject myself for the next update of my game… I don’t have a whole lot of experience with AI I’ve only dabbled and since forgotten most of what I learned however, if hes in a conversation with the player and you’ve already taken control away from the player when the dialogue is triggered, then why not have the AI move to the player when the dialogue event happens? Cause that means he’ll just stay still. I don’t know if move to itself would just confuse things though I understand your thinking. The other option would be to just tell it to stop moving when the player triggers the dialogue because again, the player will be close enough to trigger the dialogue and then he’s locked down and then the ai could stop moving and then you could call a rotate towards the player event to make it look better AND he’d go into his idle state. I don’t know if I’d use stop moving immediately just because it sounds like it could be glitchy but again, not really knowledgeable with AI.

I also remember that I often had AI go into a fail state when using MoveTo a LOT so run a print string there just so you know exactly what’s happening. I remember when I did my AI I actually ran print strings everywhere so I always knew what was messing up. AI in UE 4 is really jank. I actually didn’t even use AI a lot when I was working on my Single Player game… I opted to just use custom animations that I blended together in 3ds max built around the specific level that they were going to be in cause it was easier to do then coding AI that behaved properly. I think that’s why Bioware always used that "Actor walks off the side of the dialogue screen and vanishes trick (first noticed it in Dragon Age) cause it’s actually easier to use a canned animation in most cases.

Hey Torque, Thanks for your reply

My initial idea was indeed to tap in the EventInteract the same way it’s used in the dialogue. But I had no idea how to retrieve it in the Ai tasks.

That’s why I though I would use the overlap. This way when the player step into the npc box, the npc would interrupt his routine, whether the player decide to interact with him or not. If he chooses to interact then the dialogue and camera switch will always go nicely.

I’ll try the Moveto player target location. That might work.I’m surprised to hear the Ai system isn’t good. I though it was the “proper way” compared to graph everything within the npc graph.

That’s the current broken behavior… pretty rude :smiley:

The behaviour is working on static npc and look like that (cropped screen gif)

Hey,

Not easy to debug without having the full script at hand (for instance, when is the initial blackboard key “isTalking” set to True, for the AI to go in its Dialog task ?). It seems like your Task_isTalking and Task_MoveToSelf are immediately completing as soon as they start. What you want instead is for the task to keep going until everything has been finished.

And yes i would use the Stop Movement Immediately.

Also you may want to set an abort method to the Blackboard check “isTalking” on the right branch. So it stops any task it was currently doing.

Hey!

Thanks for your reply! What you said actually made me realize I was a bit all over the place and not super clear.

so I started to strip down everything to figure out that I should actually focus first on the sequence selector condition. Because in essence that’s what it is. On one branch the ai walk, follow a path ect an on the other he stops.

I’ve tried to do it with boolean but I ended up having something working with that.

-First I set up a IsAiTalking blackboard key as Int.
-Then I use it as decorator with value is equal to 0 or not to select the branch.
-Then In my NPC blueprint I set the value to 0 on event Begin play and assign it to the IsAiTalking BB key.


On component overlap on the NPC trigger box I set the value to 1
And on endComponentOverlap I set it to 0 again. I wanted to set it on my interact key but when I have more than 1 line of dialogue I press this key many time so it didn’t work.

Its far from perfect, the NPC looks a bit weird stopping simply when you approach and not interact, but At least it works as a branch selector. and I can add from there with a proper Stop immediatly task ect

Is it something Okay-ish :s or is there a much cleaner way?

@Genova, I’ve checked the link in your signature, Looks like we have quite a few connections in common between you current and past jobs! Small world :slight_smile: Would you recommend any free or paying ressources I could dissect to learn a bit more on this topic? I know nothing beats time and practice but it’s always good to have pointers to know how to experiment

Of course we do, Chris Lefaure asked me to check if I could give a hand to your issue :wink:
We can be in touch, ask him about my contact.