Here,
I’ve been working on enemy blueprints for my RPG game but i have gotten stuck while creating Ranged Enemy blueprint, I don’t want to use EQS or Behaviour Tree for this game, I just want to do it with blueprint only.
So My Ranged Logic Was If enemy is in the range of 500-1000 the enemy attack the player while staying still and looking at enemy at the start of attack event. If enemy outside of 1000 range it chases the player and while enemy is under 500 range it performs some king of mechanics to run away from the player.
So I created a arrow component and made it dash away from player when in close range.
But problem arises when the ai get cornered or there is wall behind them then cant go behind and get stuck.
I want help on how to make the character identify which direction has not any objects in between and dash away in that direction.
I didn’t check out the existing code you provided, but you can achieve your desired behavior by casting line traces from your enemy AI to a little bit further away. To do this, you can get a For Loop with Break node and insert your desired values into the First and Last index pins. Though it would be convenient to have 0 as the first and 90 as the last index. After the Loop Body execution pin, place a Line Trace by Channel node. Then get your enemy AI’s location by using the Get Actor Location node and plug it into the Start pin of the line trace node. After that, get the AI’s forward vector, multiply it by something like 500, add the AI’s location onto the result of the multiplication, and plug the result of the addition into a Rotate Vector node. Split the rotation pin of that node by right clicking on it’s purplish-grey pin and clicking on the Split Struct Pin option. Now drag the index pin of the For Loop with Break node and plug it into the exposed z axis of the Rotate Vector node. Once that’s done, you can plug the yellow Return Value pin of the Rotate Vector node into the End pin of the line trace node. Then, place a Branch node after the execution pin of the line trace node and plug the Return Value pin of the line trace node into the Condition pin of the Branch node. And finally plug the True execution pin of the Branch node into the Break execution pin of the For Loop with Break node.
Now, after the Completed execution pin of the For Loop with Break node, you can get that final result we got earlier to determine the end point of our line traces, convert it to a unit vector by plugging it into a Normalize node, and use it’s result to set a vector type variable. This variable will be the direction that your AI should be moving to.
You can also implement the same thing for the left side by calling the same function, but just switch the Last Index pin of the For Loop with Break node from 90 to -90. You can call them one after another before determining how should the AI keep moving, compare the last index values of the right and left sides (not the fixed last index value that’s inserted into the Last index pin, but rather the dynamic one which you can access from the Index pin) and choose the result that was in the loop with fewer iterations.
About when to call these functions, you can add a collision volume (box, sphere, etc.) that’s gonna be located accordingly with the end point of our line traces (in this example it was 500 units further away from the character) and call the functions when it overlaps a static mesh.
I hope my descriptions were clear, and hopefully they can be helpful!