How to change the way my AI work?

Basically, I have a basic AI that looks for the distance between the character and himself using a task, compare the distance with a max distance and then based on the results, move to the Player and the task will succeed, If the player is out of range, the task will fail and the character will go back to looking for random points in a radius, then moving to it.

I actually have all of that working, kind of.
I’m having weird issues where I can stand next to the AI and none of them will come to me and sometimes they do, it seems that each AI are executing the task after the other AI has finished, so each AI takes turns in doing the event rather than them all doing it at the same time, how do I fix this?

EDIT: Just got some pictures to show you, sorry for the quality.!

BTW what version of UE are you using?

I don’t understand what you mean, could you explain a little bit more? thanks for the help, I am running UE 4.5

I couldn’t find the Receive Execute Event in my copy of UE 4.5 release.

Oh ok I got it! You are using the tutorial on the wiki here right?

I deleted my answer! Seems I didn’t look clearly…

I guess the issue is that in compare float, the middle execution pin is executed due to floating point errors when the AI is really close to you. Or the other problem could be in Simple Move To Actor, when it would be too close to you, your player would be colliding with the AI and it would be unable to move. I don’t know about the other problem though. Ill try it out and see what I can find.

Your PlayerLocatorTask, if some conditions are met, calls SimpleMoveToActor and finishes the task with Success. The problem here is what happens next, as the task succeeds, the controll goes back to BT’s root node, which runs the tree from scratch, making PlayerLocatorTask run again… and again… and again… you get the drill. The ideal solution is not to call FinishExecute untill you really want the task to finish (like for example when AI is close to the player). FinishExecute simply results in given task declaring it has finished whatever it was supposed to do, and it’s time to look for another task.

Hope it helps,

–mieszko

MieszkoZ, First, thanks for the reply, I understand what you are saying by that and I couldn’t really find a way to get it to work, So what I did, I got the ZombieIdleWalkTask to check on every execution the distance between the zombie controller and the player pawn then set a boolean to true if the player is within the radius, after that I send the information to the Player locator task which will then move the zombie towards the player, the issue I came into with this approach was for some, the distance being calculated doesn’t follow the zombie, it follows its controller, the controller stays where the zombie has spawned, so the zombie only comes close to me if i go to its origin point, not if i actually go to the zombie, is there any work around ? or maybe even a tutorial on getting ai to go to the player, because i’m clearly struggling trying to work this out on my own, help is appreciated as always :smiley:

Yeah, regarding AI’s location, always use ControlledPawn's location, not AIController's. Controller never gets moved and is always, like you’ve already noticed, where given AI has been spawned.

Cheers,

–mieszko

I assumed so but the reason I didn’t do that was because when I get the distance from the AI Pawn to the Player, it always comes back as 0.0, I think I know why, I’m referencing to the Blueprint and not the actual object in-game, Just by thinking about it, I can probably fix this by spawning the AI in by bp’s? Is that right? Is there any other way? (although eventually I do want them to spawn in by blueprints, for now I’d like to be able to drag and drop)

Also, My ZombiecharacterBP is a CharacterActor not a Pawn, should this be a pawn?

Looking into it further, I can see that my reference is giving off “None”, that and the internet confirms my theory of it not referencing to the in-game actor, I keep seeing people talk about the Get all actors of class node but it turns them into an array and I don’t know how to derive the specific one i’m trying to control from the array.

Thank you

Character is derived from Pawn do it’s fine.

Regarding usage of drag & dropped AI it shouldn’t make any difference, except that for manually placed AI you need to trigger their BT manually.

Sorry, but I can’t help you more without you showing more data, or (ideally!) sharing a stripped-down version of your project. Feel free to send it directly to me at mieszko.zielinski at epicgames.com.

–mieszko

Alright, sorry for all the questions all I really want to know is when I have a reference of a “Character” what would be the proper way of getting the pawn from it?

I’d happily send you the project, it’s 1.6gb, I’ll do some stripping if you want.

How do you reference your character? And where exactly?
Character is a pawn, you don’t need to get one from the other.

Okay so I’ve got a picture that gets straight to the problem, the “Get Distance Node” is printing 0.0 and i’m getting an error saying that the “ZombieRef” is set to None, sorry that the nodes are all pushed together, it was so I could get it in one shot.

The calculated distance being 0 is the result of ZombieRef being None.
The key question here is where is ZombieRef being set? The thing is BP implementation of a BT node cannot have a direct reference to an actor on a level since BT nodes are assets, level-agnostic. ZombieRef needs to be set in your BT task implementation.

Yeah, that’s what I was trying to say before, that the ZombieRef is None and I can’t find a way to get the in-game reference, The way I’m setting the ZombieRef value is on spawn of the zombie, this is my spawn logic, I just drag and drop this bp in the map and it will spawn within the box boundaries.

(SpawnRadius) = BoxComponent.

You just need to put your zombie pawn ref somewhere you can access from BT node. If I understand correctly, all you need to do is to cast pawn of AIController that’s using the three, to your ZombieCharacter. If that’s None then either your pawn is not of given class or it’s None altogether.

I’ve noticed my problem, I need the BT to store the values, I have solved the problem thanks to your advice, thanks alot, I didn’t know enough about what BT did so i’ve done some digging and fixed it.

Thanks.