Reputation: 11
I have a ship and I want the Ship to follow the mouse, it does that fine and dandy. When forward and backwards are pressed it goes towards and away from the mouse perfectly, but I can not figure out how to make the left and right buttons make the ship circle around the mouse in a clockwise/counterclockwise direction.
I have tried to take the ships location, and the mouse's location, creating a slope, and then getting the perpendicular to that slope, but that doesn't work either.
How can I achieve this? I do not think it needs code, more of an equation, but if there is code, please tell me.
Upvotes: 1
Views: 464
Reputation: 63
You need the parametric form for the equation of a circle. Since you want it centered about the mouse's current location, you need an offset translation. Try something like:
float radius = 10f;
float shipX;
float shipY;
float angle = current_angle; // update this to animateshipX = mouseX + ( radius * Math.Sin(angle));
shipY = mouseY + ( radius * Math.Cos(angle));
Upvotes: 2