Quote:Original post by Bob Janova
You don't need trig to do that:scalefactor = speed / sqrt(sqr(cursor_x - player_x) + sqr(cursor_y - player_y));traX = (cursor_x - player_x) * scalefactor;traX = (cursor_y - player_y) * scalefactor;
Of course, which is faster depends on whether cos and sin beat sqrt and sqr. But the chances are they don't.
ok, i tried that, and it work fine, BUT, sometimes the bullets are far away from the center of my cursor. sometimes they are perfectly in the middle, sometimes they are off by 30 pixels. my code:
pistol[c].x = player->x;
pistol[c].y = player->y - 3.7;
pistol[c].angle = 7 / sqrt( ( (cursor->x - player->x) * (cursor->x - player->x) )+ ( (cursor->y - player->y) * (cursor->y - player->y) ));
pistol[c].trajectoryX = (cursor->x - player->x) * pistol[c].angle;
pistol[c].trajectoryY = (cursor->y - player->y) * pistol[c].angle;
what wrong??