|Topic was automatically imported from the old Question2Answer platform.
Greetings from Brazil. I’m developing a 2D shoot’ em up game In this game genre, is quite common to have enemies that shoot aiming at the player’s current position. Since in my code all positions and speed are represented with 2D vectors, the formula to calculate the desired enemy shot direction is quite simple: (playerx,playery)-(enemyx,enemyy).
However, I want to try a different twist. Instead of having enemies that aim at the player CURRENT position, I want to create enemies that instead aim at the player FUTURE position. Both player speed and enemy bullet speed are constant. Is there any vector formula that I can use to calculate the enemy bullet direction, so it’ll intercept the moving player? Thanks in advance!
Whether or not there is a formula, and how complex it is depends very much on what you Expect of the players behavior.
Are you doing a top down shooter and expecting the player to continue in straight lines? In that case…
(Vector_to_player + Player.Velocity* distance_to_player/BulletVelocity ).normalized()*bulletVelocity will give a reasonable approximation.
If you are in a 2d platformer with gravity involved, things get more complicated.
nineGradens | 2019-07-19 21:04