The PawnSensing component has an OnSeePawn event, but lacks any sort of OnExitPawn event. I googled it and found I can attach OnSeePawn to a boolean and set it to true once the event triggers. The AIMoveTo can turn it back off once the pawn fails or succeeds in arriving at its destination. This caused my robot to behave strangely when I tried to attach a basic finite state machine to it. I can’t seem to find a way to get that boolean to turn itself off in a natural way after the player leaves the AI’s sights. Or worse, tries to enter again before the robot was done doing what it needed to do. This feels like a workaround that only halfway fixes the problem, I thought. Well, if I’m working around it, why not just go make my own?
Not using the OnPawnSee event at all. In stead, using GetForwardVector * float distance and RotateVector with a given float angle, I can add that to the AI’s world position to simulate the bounds of my own cone! Well, box-cone? It wound up having four corners like an ever-scaling plane because I didn’t turn them into a circle. That’s alright, though. All I need is the minimum and maximum coordinates of the cone in a given position and I can check it for the player! I initially had red debug lines drawn in front of the AI to represent its FOV, but I later removed it for coherency in the blueprint.
Cone Vector Math:
And finally, the big finish. I get to reap the benefits of my superior maths!
The second event I didn’t need to create but actually could have left in the previous event:
It doesn’t work. I figured out why after adding those cubes on the bottom that follow the min/max vectors. Honestly, I should have guessed from the start that it wouldn’t work. But now, I’ve got to do one of two things, figure out what formula to add to my vectors to make their distance from the AI scale properly in relation to the player? Or think harder about a way to better meld with PawnSensing? OR OR maybe I should get off my butt and learn AI Behavior Trees. Also, is there a way to check if a vector is in between two other vectors, or am I already doing that?
Basically, what happened is this; The angle around the AI, of course, makes a 360-degree circle around it in world space. It felt simple to add the player distance to the forward vector of the AI in order to get our bounds. Unfortunately, this means that the points of interest are not actually next to the player at the time. For this script to work, the player would have to be within a thin area margin in order to be detected by their center pivot. Depicted by the line in between points A and B.
I’m sure anyone who is decent at vector mathematics can elaborate on this and maybe improve it?
Or tell me how silly I was for thinking this would work on the first try.
Sorry if the scripts are hard to read. It’s almost 1am and I’m tired!
Will update in the coming hours or days.
There wasn’t much purpose to this. I soon realized that AI Behavior Trees have the FOV capabilities I want, it’s just a matter of learning it. This project became more of a “can I do it this way?” sorta thing. It was a fun learning experience and something I might tinker toy with some more.