So I have tried many different ways to get this to work.
What I am trying to do is simple.
Player walks into collision box attached to AI, which makes AI runs in the opposite direction away from player.
Red target is where AI stops at and the arrow is the direction he goes to get to it.
One way I attempted to do this was to use the get random point in radius node, I thought if its possible I could find a way to cut the radius in half and have it work as a half circle, and then the AI would run into a random spot in there. But I have not found a possible way to do this even through trying to get a circle diameter and such and calculating it with pi and other different combinations but no luck.
I also kept reading up about vectors and thought that they might be my answer but have not been able to put that to use either.
Using Vector math is the best solution. You can get the direction of the by using the getlookAtRotation and rotating the AI’s forward vector (Not location or rotation) by that amount (essentially saying that this is the direction of the player relative to me.
From there you can use a cross product to find out what direction is 90 degrees from there. You could also use the dot product and some logic on the result. There are examples Herein cpp but it’s just math and results so it works in blueprints by plugging in values to nodes.
That will help give you a direction and then you can use the same types of checks (maybe with a random unit vector in cone of the inverse of the direction and a 40 degree cone to get the flee direction.
In the AI moveto node, I use the actor location instead of the actor pin. I break the pins and multiply the x axis(forward axis) to -1, giving you the inverse.
P.S. I created a variable so I can set to 1 or -1. Why? So that I can make the AI run from and toward the player based on condition, i.e is being hurt, lost/gain advantage, etc.
Thanks for your help KinDaCreator. I will test your idea out, I in the meantime found a different solution to my problem.
What I did was in my actor blueprint in the view port I made a simple collision box and placed it far away behind the actor.
Then I edited it so that under certain conditions the AI will run to that box’s world location when it see’s the player.
I will try out your code for this though, my code is probably not the best way to do what I was trying to do. Vectors are hard.
I wrote an AI Task that fires a line trace 8 times, in 45 degree rotations around the actor. Then it compares each collision (or end point) to find the furthest location from the player. This seems to work fairly well. It was difficult for me to keep up with the fleeing actor.
You could take this a step further and have it run another 8 line traces from each location it finds for a total of 64 possible locations. It would use the furthest navigable location from the player. I didn’t take it quite this far but it’s possible and there was no lag at all running 8 line traces.