Reputation: 1976
I'm trying to make a very simple game. In it I have objects (Circles
) that have an xDirection
and a yDirection
, both of which can range between -1
to 1
.
I have another object that can be rotated by the user (Pointer
) atop of the Circles
. I've achieved this rotation by copying some code I found online that gave me the angle
of the Pointer
from the y-axis that runs through the center of the Circle
. (This).
Now i'd like the "gameplay" to be a case of the user angling the pointer into the direction he wants the circle to move. If I have this angle, is there a way I can calculate xDirection
and yDirection
for the circle?
Really appreciate any help, I know I need to work on my math! Oh and I'm technically working in javascript, but i'm thinking there's a purely mathematical solution that could be implemented in many languages?
Upvotes: 1
Views: 964
Reputation: 298106
If I'm reading your problem correctly, this should work:
x = -sin(angle)
y = -cos(angle)
Upvotes: 3