I'm creating a simple game using PaperJS and I'm currently stuck on a small part of it.
In the game, there is a player (just a circle) who has two hands (two smaller circles)
I want the hands to always point towards the mouse position, but I can't figure out the equation needed to do so.
Here's some of the code I have so far, I just need help filling in the blank...
view.onMouseMove = function(event) {
var mouseX = event.point.x;
var mouseY = event.point.y;
var rotation = ???
playerHands.rotate(rotation, view.center)
}
Here is a diagram of what I'm trying to accomplish:
paper.js
, but recently I have answered this question regarding rotation towards the mouse. Maybe it will be helpful. I suppose you should write something like this:var rotation = Math.atan2(mouseY - view.center.y, mouseX - view.center.x) * 180 / Math.PI
– Kirill Simonovatan2
is the answer ... to get correct equation how ever we need to knoe your coordinate system (where x,y points and which way angle is increasing) otherwise you would need to play with+/-
combinations ... You need player position (instead of view center... if they are not the same) and mouse position for this as input .... also you need to know if angle is in[deg]
or[rad]
and where is its zero – Spektre