Hi,
I'm trying to add a gun that fires in the direction of the mouse from a centre point, this code only fires accurately when my mouse is incredibly far away (but without changing the angle) and I want it to be accurate at all distances. I've been stuck on this for ages, I know my maths is probably wrong but I just don't know why it works at some distances.
Thank you, sorry if this is a repeat question
//where it starts
int aky = akSprite.getPosition().y;
int akx = akSprite.getPosition().x;
//checks for mouse position
int mousey1 = this->mouse.getPosition().y;
int mousex1 = this->mouse.getPosition().x;
//how many large or small the movement is
const int distance = 30;
std::cout << "\n The mouse position used is x: " << mousex1 << " y: " << mousey1 << "\n The launch position is x: " << akx << " y: " << aky;
//finds the height and width of that position and lowers it to movable values
travely = (mousey1 - aky) / distance;
travelx = (mousex1 - akx) / distance;
//global variable for bullet's position
totalx = akx;
totaly = aky;
//the bullets position updates constantly elsewhere while this is only run when the fire key is pressed
std::cout << "\n The current MOVEMENTS ARE x: " << travelx << " y: " << travely;