Posted: 16th Dec 2011 9:39
I'm currently trying to figure this out in AppGameKit, with no avail. But as a simple example, let's say I have an arrow placed in the middle of the screen. It's location is fixed towards the middle, but I want it to rotate towards and point at the current cursor position.

How can I go about doing this? I figured I could try it via cos/sin (make three points from the info and form a triangle), but it isn't working the way I planned. Any suggestions?

EDIT: Found a post on MSDN and found a solution that applied to AGK:

+ Code Snippet
spriteAng = atanfull(spriteX - mouseX, spriteY - mouseY)
spriteAng = spriteAng + 180
    setSpriteAngle(spriteID,spriteAng)
Posted: 16th Dec 2011 12:17
Thanks for sharing the answer with the community- it's so much better than "I got it, please delete this post"

I had a similar angle problem which I'll share. I needed to know the smallest angle between 2 points on a circle, so I could rotate the circle from one point to the other...

+ Code Snippet
angle = current.angle - last.angle
if angle > 180 then angle = angle - 360
if angle < -180 then angle = angle + 360
short.angle = angle# + last.angle


The sign tells you which way to rotate, the value tells you by how far.
Posted: 16th Dec 2011 12:30
Just adding to answerman's code, the +180 bit is an angle offset and will vary depending which way the object in your image is facing. For example a ship facing to the left will have a different offset to one facing to the right.
Posted: 16th Dec 2011 23:33
Haha thanks Hodgey. I didn't even think of that, my sprite was pointing upwards when I created it
Posted: 17th Dec 2011 7:55
This code will need an aspect ratio adjustment when using a percentage based resolution too:
+ Code Snippet
spriteAng = atanfull(spriteX - mouseX, (spriteY - mouseY)*getDisplayAspect())
spriteAng = spriteAng + 180
    setSpriteAngle(spriteID,spriteAng)