I am developing a kart racing game. In it, the players fight with each other while racing.
There were several ways I tried to add attack AI to the enemies and the player.
- When the user clicks on the attack function, it throws raycasts in the certain area; if enemy is found then the user gets presented with the weapon and auto attacks occurred.
Later I moved on from this code for two reasons, first very dirty and highly unoptimised and second it's only able to calculate limited distances (not for missile weapons which are long range); a new approach needed to be implemented.
After thinking and researching I tried Physics.Overlap; this did solve my optimization problem with short range weapons but still the problem of long range persists.
Thinking around more I came up with other ways to implement long range attack, i.e., by spawning one collider just a little behind the player and it will go foreword until a certain distance and if the enemy gets found it will inform the player and the weapon will be spawned and attacked.
Though that third approach looks good so far, the problem arises when the game gets high pace as the collider sometimes do not catch the other players or get too slow to catch the other players and result of that buggy attack look.
So I would like to know: is there any other way to implement long range attacks considering it is a kart racing game?
Any help will be appreciated