Rotate 2d sprite towards pointer

Posted by Phil on Game Development See other posts from Game Development or by Phil
Published on 2013-06-27T18:42:54Z Indexed on 2013/06/27 22:29 UTC
Read the original article Hit count: 193

Filed under:
|
|
|
|

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?

© Game Development or respective owner

Related posts about 2d

Related posts about JavaScript