I know my trigonometry but I have no idea how to put it into code
I have to variables
speedX and speedY
I want the direction to go to my mouse
Sorry its hard to explain I hope you understand
I know my trigonometry but I have no idea how to put it into code
I have to variables
speedX and speedY
I want the direction to go to my mouse
Sorry its hard to explain I hope you understand
Here is some code from one of my games to sent Enemy Projectiles in a straight line towards the player.
These variables are declared in the constructor.
x,y,targetx,targety are floats
projectilespeed = ....
targetY = Player.y;
targetX = Player.x;
x = startX;
y = startY;
shooterX = startX;
shooterY = startY;
double xx = shooterX - (double) targetX;
double yy = shooterY - (double) targetY;
angle = Math.atan2(yy, xx);
and in the update method i adjust the projectiles x,y coordinates:
public void update() {
x += projectileSpeed * -Math.cos(angle);
y += projectileSpeed * -Math.sin(angle);
It didnt seem to work im more for aiming with mouse?
Am I correct in thinking you want the player to rotate to the mouse location and then fire a projectile towards the cursor location?
pretty much
Take a look here: