I’m hoping someone can help me, i’m trying to figure out how to create an AI that will only attack when not in view of my FPS camera.
So far i have a very basic AI that when in range will follow me.
i have tried to create a cone that fills my FOV, hoping i could use a simple collision box that could pause the AI, so far i cant get it to work.
Another option i would like is for the AI to attack when in darkness, and if i look at AI with my flashlight, again it pauses, ready to follow when out of view.
Theres a few videos of this trick on youtube, but i cant figure it out fiqure it out.
one is to project the enemy to the cameras screen using ProjectWorldToScreen. If the enemy is not visible on the screen he could attack, you only need a distance check and it would work.
Another popular way to solve this is DotProduct. DotProduct should take two normalized vectors and and return how “equal” they are, return 1 when they are completely the same, -1 if they are opposed and everything in between in a range from -1 to 1.
You can use this to calculate the direction the AI stand towards the player and check this against the camera forward vector and define a treshold in which attacks are possible.
The flash light thing could just work the way you tried, make a cone that fits the light and enable overlap events on it.
Yeah, you just need to check if the bool is true or not. No need to do viewport stuff. If the bool is true, then the AI Character is on the players screen. The ScreenPosition can be used to tell exactly where the Pawn is on the screen. It is scaled to the resolution. If your resolution is 1920x1080, then the ScreenPosition will have values from (0,0) to (1920, 1080) depending on where the AI character is on the screen.
Also one thing to note, it for characters GetActorLocation gives the location at the bottom of the capsule, most likely the feet of the character, you probably want ot check against the eyes or something.
Could you explain like I’m 5, I have no idea what I’m doing with booles and how to make them true or false, I tried google and haven’t a clue what to do