As the title suggests, I’m stuck. I’ve tried to figure this out for the past 3 (frustrating)days and I just can’t get a target location in the opposite direction of the player from the AI’s perspective without strange issues like the AI always running away to the left, or right (not caring where the player is) or it getting to a spot where it’s just happy to sit despite the target location being updated or updated to the same location over and over again.
My AI is very simple and in 2D, I just need the AI to move away from the player when it has focus on the player(My behavior tree is working in that sense, I’m struggling with my behavior tree task that sets the “hiding position” vector that my “MoveDirectlyToward” task uses as a target location. Specifically I need the task to get the direction between the 2 actors, player and AI and set the blackboard value “hiding position” (Used by the movedirectlyto) to some distance away in that direction.
I am not sure if it needs to just run away, or run away to a certain location
You can use “find look at rotation” between the AiChar and PlayerChar, and get the forward vector of that rotation. Then you can find a location in the negative x-direction of that vector which will then be in a line directly away from the player, and use this as the target location.
If moving to a specific location. You can get the distance to both the Ai and the Player, and if the distance to the Player is greatest, then that must mean that, this location is away from the player.
You are correct it doesn’t have to be a specific location just away from the player, using your advice I have a “find look at rotation” node which is fed from both the player and AI’s “get actor location” nodes, it’s output is fed into a “get forward vector”- That output is put into a “vector + vector” node where I put -20 for the x axis. Final result is the AI seems to find 1 spot it’s happy with and it just sits. I suspect I’ve misinterpreted your advice. How would I do this “Then you can find a location in the negative x-direction of that vector”? I assume not by using a Vector + Vector with some arbitrary -x value?
That was helpful and initially the AI runs away now, but if I follow it until it gets to it’s point (or back off so that the behavior tree goes to idle behavior in this case returning back to where it spawned) if it sees me again, it flies toward me (past me in the opposite direction). Rinse and repeat, basically every time it sees me it chooses the opposite direction that it should.
You know what, I posted that comment with the screen shot and I found an obvious problem, I needed the pawn location but accidentally was using the controller location. The math as posted above with the change I just mentioned now works! Thanks so very much for helping me out with this! I seriously appreciate it you made my week.