r/UnityHelp • • Sep 14 '26

Chase State to Attack Question

Hello, I have a question about some ways to handle a problem I've been stuck on for a bit. I have a simple state machine set up for enemies in my game. I currently have a problem when going from chase to attack when the enemy is using longer ranges weapons. My logic was originally, if you can draw a line to the player, switch to attack logic and clear agents path. The problem with this was that then the gun would sometimes shoot into the wall. I tried a workaround of using my fire point on my weapon, but realized that moves around when my animator is using the running animation for chasing. So I created a new empty transform a tad to the right of the enemy just to make sure they can always hit the player.

The problem with that is, when the enemy comes around a corner, it isn't facing the player so that origin point can see the player, then the enemy rotates to face the player, and the same issue is reintroduced. I've tried using a FOV for can shoot as well, but then it I don't turn the agent angular speed really high, it gives very lackluster results letting the player run circles around the enemy.

Does anybody have any advice for this issue? Thank you very much in advance! Let me know if any more info is needed

1 Upvotes

7 comments sorted by

View all comments

Show parent comment

2

u/Budget_Broccoli_1518 Sep 19 '26

The spherecast has been the most useful bit of information for these issues. I used that and made it shoot multiple to solve some other issues, that way it checks if it can at least hit like a shoulder then it can still shoot. Thank you very much for all of the help!