How do I make something move towards the play when not in view, and stop moving when visible

Hello. I am working on a little project, and I have been working on something, but no luck. I am trying to make an AI that will move when not visible, but will stop when you look at it.

Any help is appreciated!

This is one way I can think of doing it. Do this inside your AI’s class, and replace Cube for your AI player.

So get the distance between the player and the AI by subtracting their locations in world space, then normalize this to get a value between 0-1. Next find the Dot Product of this normalized vector and the Player’s Forward Vector. If the return value is >= 0.0 then they are facing away from the AI, if it’s <= 0.0 they are facing towards the player.

Edit: From the branch you can then do AI Move To, to move to the Player.

How do I get the blue nodes xD

I just did this in the Level Blueprint quickly, inside your AI character you could create a variable and change the type to be your player character. Then in the AI’s Begin Play, set that variable to “Get Player Character”. Then you can use that variable in place of the “FirstPersonCharacter2” nodes in my image. The node that’s called Cube, replace that for the “Self” node.

If you’re still unsure, let me know and I’ll try and remake it using an AI and Player class.

Got everything, however the AI still wont move, not sure how to make it do so.

Here’s What I tried: blueprintUE | PasteBin For Unreal Engine 4

Doesn’t seem to move.

Make sure the AI is inside a Nav Mesh.

Unless I need more than a NavMesh Bounds Volume or whatever I do

Hello, i haven’t use it since a long time but maybe trouble comes from that in your ai move to, the pawn input would be self and target actor input player character not the opposite as actually.

BP posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4 Here’s what I have now

Still doesnt work, and I get these errors:
Error Blueprint Runtime Error: Accessed None trying to read property CallFunc_GetAIController_ReturnValue from function: ‘ExecuteUbergraph_SCP-173’ from node: Teleport in graph: EventGraph in object: SCP-173 with description: Accessed None trying to read property CallFunc_GetAIController_ReturnValue
Error Blueprint Runtime Error: Accessed None trying to read property CallFunc_GetAIController_ReturnValue from function: ‘ExecuteUbergraph_Testmap’ from node: Teleport in graph: EventGraph in object: Testmap with description: Accessed None trying to read property CallFunc_GetAIController_ReturnValue

Try this as a test inside your AI’s class: Move To + Look At Actor posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4

I’m only using a static mesh to test this, not a skeletal mesh or proper AI. You’d need to use Behavior Trees and Blackboard with BehaviorTree Task Nodes to properly use AI if you’re not already.

Try this series. Looks like it goes quite in-depth in creating basic AI using just Blueprint: Unreal E
Tesla Dev also explains it kinda well: Unreal Engine 4 Tutorial - AI Behaviour Tree - YouTube

Works pretty much the only way I need it to, however could I make it so it wont go inside the player, and so it will move when you can’t see it through objects, finally how about force it to go around objects?

You’ll need to set up Behavior Trees with tasks properly to do stuff like that properly, if you didn’t already, you should really check out Tesla Dev’s video, https://www.youtube.com/watch?v=h0Kb42oCoYg he explains how to move the AI around a nav mesh which will force the AI to go around objects.

If you want to make it so the AI will also move when the player is obstructed by an object there are many ways you can do this. The easiest is to use the Pawn Sensing Component, I know it has an OnSeePawn event so you could use that to say stop moving the AI when this event is triggered. Alternatively you could have a sphere collision of however big you want the AI to be able to “see”. OnComponentBeginOverlap cast to the player and do LineTraceByChannel with the start location being the AI’s world location and the End being the Player’s world location. On the Hit Actor, cast to the player, if the cast is successful that means there is nothing blocking the view between the AI and Player.

Pawn Sensing Component: https://www.youtube.com/watch?v=59INcP9Vsmo

Done everything I need except where it will move through an object, and it will move when your vision is obstructed. I connected the return value to the condition on the branch, and still no luck. Not sure if I missed anything or what the case is.

Yeah with the SetActorLocation it will move through objects, I only did SetActorLocation as a test to make sure it moves etc., you will need to use the AI MoveTo node inside a behavior tree task class which will use Unreal’s A* pathfinding algorithm on the nav mesh to navigate around objects.

UE crashes when I use AIMoveTo