-1

Im kind of stuck with this problem

i created this function but for some reason i can only move the object to the right of the Player.

If i try to move the object to the Left of the Player is goes right.

here is my approach:

int Speed = 8;
int x = Player_x - Mouse_x;
int y = Player_y - MOuse_y; 

float deg = atan(y / x);

float erg_x = Speed * cos(deg);
float erg_y = Speed * sin(deg);

erg_x/y are the numbers i use at the end to move the Object.

Please help me :)

Dolfos
  • 98
  • 1
  • 9

1 Answers1

0

As explained here, atan only works in the first and fourth quadrant. Since going left involves the second quadrant, this isn't going to work.

As such, you'll want to change

float deg = atan(y / x);

to

float deg = atan2(y, x);
Community
  • 1
  • 1
Emily
  • 1,030
  • 1
  • 12
  • 20