Moving from point A to B - Shooting and movement

Hi guys so i’m looking into making my enemy get the position of the player and then fire a bullet towards the previous location and was wondering what the best way to do this was. (My game is a 2D vertical scrolling game and the enemy shoots down towards the player)

I’ve searched online but i’m a little confused right now. People seem to suggest using trig and was wondering if anyone could point me in the right direction? A common piece of code I found was this:


double dx = player.x - enemy.x, dy = player.y - enemy.y;
double distance = Math.sqrt(dx*dx + dy*dy);

double multiplier = moveSpeedOfEnemy / distance;

double velocityX = dx * multiplier, velocityY = dy * multiplier;

I’ll likely have to brush up my maths as this is confusing me but if anyone can explain exactly what I should do and any useful resources then it would be great! :slight_smile:

Sorry if the question is a little vague but just ask if you need more info etc :smiley:

Thank you