0 votes

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!

enter image description here

asked May 31 in Gossip by Leandro (102 points)

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....

(Vectortoplayer + Player.Velocity* distancetoplayer/BulletVelocity ).normalized()*bulletVelocity will give a reasonable approximation.

If you are in a 2d platformer with gravity involved, things get more complicated.

1 Answer

0 votes

You would need to learn about a math library specifically for this.

answered Jul 12 by Dooowy. (216 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.