开发者

How do I make make things move properly at angles in Java

I have a class called Bullet in a sort of birds eye view shooter game. I used to run it simply so that it moved based on an inputted direction, which could only be north south east or west. I 开发者_开发技巧now want to make it so you can shoot at any angle, but if I shoot it is inverted on the Y axis (Meaning if I aim Up it goes Down). Here is my code (Yes i did remember to convert to Radians). Each bullet is made of a small line and here is an exerpt from the move method:

double scaleX = Math.sin(angle);
double scaleY = Math.cos(angle);
x = x + (MOVE_SPEED * scaleX);
x2 = x2 + (MOVE_SPEED * scaleX);
y = y + (MOVE_SPEED * scaleY);
y2 = y2 + (MOVE_SPEED * scaleY);

x, x2, y, and y2 all dictate the points on the line. I only know a bit about Trig so any help would be fantastic. Thanks!

EDIT: I made a mistake earlier in saying it goes right instead of left and vice versa, but it goes up instead of down and vice-versa, and acts properly left and right.


This is too obvious to be correct: Change

double scaleY = Math.cos(angle);

to

double scaleY = -Math.cos(angle);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜