Spawn actor from class on the (player’s location + Get the player camera’s forward vector and multiply it by
negative DistanceFromThePlayer, except for the Z location). You can avoid the enemy from spawning behind a wall by line tracing to the spawn location from the player.
I can show you an image of how the BP would look if you need it
And because I bet you will want this aswell. For the rotation of the enemy you can use a node called Find look at rotation.
Sorry, I forgot the whole question after I started coding. I updated the code with everything you want.
So I start by setting a timer on event begin play, in the picture its between 0 and 30 seconds.
Then I line trace because the player could be standing with their back to a wall and you might not want the enemy to spawn behind the wall. In my case the enemy will spawn right behind the player if their back is right against a wall.
A line trace is a function that sweeps/moves from one position to another in one frame and if a X thing is in between those two positions it will get information about X thing. In my case I only get the hit location. More info here: WTF Is? Line Trace For Objects in Unreal Engine 4 ( UE4 - YouTube
Ok so spawn the enemy after we know whether the players back is too close to a wall, make sure the enemy is facing the player with Find look at rotation and start the timer all over again at a new random time.
Hello, I have been working on a horror game for my college project and I only have m AI left. I have created an Ai that can patrol the environment (a house) and can catch the player. However, I want the AI to spawn at random times near the player (for example behind the player) instead of having the AI patrolling the house all the time.
I have watched tutorials on spawning enemy AI but they are about spawning multiple enemies at random locations. I don’t know how to make only one AI spawn near the player at random times. If you could help give me an idea of what to look into, I would really appreciate it.
Thank you for your reply.
Yes, I would really appreciate it if I can see how it would look like.
Thank you so much! I will work on making it spawn randomly.
Thank you, this has helped me a lot!