Posted June 17, 2022 by Arcane Studios
In this Tech Discussion I will be explaining how I solved a problem with our ranged enemies’ aiming logic.
Before the fix, when our ranged enemies fired a spell they would do the following:
The problem with this setup was that once the spell spawned it automatically aimed at the player, regardless of where the enemy was pointed, resulting in wonky situations like this where the enemy character placed their hand in front of them but the spell fired off to the side:
Additionally, this setup rendered useless the warning the player got from the enemy’s animation because by the time the spell spawned, it aimed right at the player even after they tried to dodge.
Here is the solution I came up with:
After spawning the projectile, cast a ray forward from the enemy:
If the ray has no hits, fire the projectile at the end of the ray:
If the ray does hit, aim at that first point:
Now if the player sees the enemy start their cast animation, they will be able to move out of the way and dodge the attack:
Author: Reilly da Silva