D
D
Dima2017-06-19 13:46:50
Mathematics
Dima, 2017-06-19 13:46:50

Find the x and y coordinates of a corner?

In the game, by clicking left or right, I change the angle, along with this, the picture rotates in the right direction. But the problem arises when I want to move the sprite forward. Need coordinates for x and y. I need this to move the sprite to the next x and y coordinates
. Note that this method is not suitable.

pd.x = 180 * cos ( angle ) + pd.x + 64;
pd.y = 180 * sin ( angle ) + pd.y + 64;

pd.[yx] is the character sprite.
64 is half the size of the picture.
angle is the angle.
Why is this method not suitable, because when my sprite rotation reacted to mouse movement, the calculation of these angles constantly rotated in the direction in a circle.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tsarevfs, 2017-06-19
@ztstzazz

pd.x += sin ( angle ) * 64;
pd.y += cos ( angle ) * 64;
Most likely so. If the angle is in degrees, then you need to convert to radians to calculate the sine and cosine:
pd.x += sin ( angle / 180. * pi ) * 64;
pd.y += cos ( angle / 180. * pi ) * 64;

D
Dima, 2017-06-19
@ztstzazz

Thanks, this helped.

pd.x += sin ( angle / 180. * pi ) * 64;
pd.y += cos ( angle / 180. * pi ) * 64;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question