I'm using Crafty.js and am trying to point a sprite towards the mouse pointer.

I have a function for getting the degree between two points and I'm pretty sure it works mathematically (I have it under unit tests). At least it responds that the degree between { 0,0} and {1,1} is 45, which seems right.

However, when I set the sprite rotation to the returned degree, it's just wrong all the time. If I manually set it to 90, 45, etc, it gets the right direction..

I have a jsfiddle that shows what I've done so far.

Any ideas?


1 Answer 1


With some experimentation, your angle appears to be inverted, but otherwise correct. Negating your angle works:

obj1.rotation = -Engine.degree(pos2, pos1);

And the modified jsFiddle.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .