Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Rotate sprite towards current mouse location

Author
Message
anwserman
13
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 16th Dec 2011 09:39 Edited at: 16th Dec 2011 09:55
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:



Hi there. My name is Dug. I have just met you, and I love you.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
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...



The sign tells you which way to rotate, the value tells you by how far.

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
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.

anwserman
13
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
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

Hi there. My name is Dug. I have just met you, and I love you.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th Dec 2011 07:55 Edited at: 17th Dec 2011 07:56
This code will need an aspect ratio adjustment when using a percentage based resolution too:


Login to post a reply

Server time is: 2024-11-22 21:00:36
Your offset time is: 2024-11-22 21:00:36