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 / Move 360 degrees and maintain angle?

Author
Message
Crabbages
14
Years of Service
User Offline
Joined: 12th Aug 2010
Location:
Posted: 9th Mar 2012 23:23
Hey guys! Wonder if you can point me in the right direction.

I had used 'setspriteoffset' and 'setspriteangle' to have my sprites rotate around a certain point. I've been trying to have sprites stay upright while moving in a circle, but because only the angle changes and not the X or Y position I'm not able to have the sprite keep its current position AND face upright.

I thought of animating the image to turn the opposite way...but that seems a bit drastic.

Can anyone tell me what I should be doing instead?
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 9th Mar 2012 23:47
Quote: "I'm not able to have the sprite keep its current position AND face upright.
"

You might need some trigonometry here. I wrote a few functions for the UCF project (see sticky on this board) to simplify the process though.

A small example (project attached as well):


Attachments

Login to view attachments
Crabbages
14
Years of Service
User Offline
Joined: 12th Aug 2010
Location:
Posted: 10th Mar 2012 02:20
Hey Hodgey, I couldn't work out how to set the speed.

Vel = distance to centre of circle? (could the centre be set as a coordinate?)

I increased the Vel and that made the circle larger.
I increased the angle to make it go faster but that made the circle smaller(and without correcting every 360, my sprite eventually flew away to the right).

So, it did work for rotating! Thankyou!
but I'd also need control of the speed at which the sprite travels.

I'll continue to play around though, then maybe look into the dreaded land of trigonometry... see what comes up and report back!
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 10th Mar 2012 11:33 Edited at: 10th Mar 2012 11:33
Quote: "Hey Hodgey, I couldn't work out how to set the speed.

Vel = distance to centre of circle? (could the centre be set as a coordinate?)"

Yeah, the functions actually aren't really designed for orbiting, my bad. But there is a solution.

Try these:


Replace the New xy value functions with those. I haven't actually tested them as it's late over here but they should work. Here's a nice explanation of the maths if the functions don't work and/or you get stuck.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Mar 2012 13:18
Watch out for the aspect ratio problem if you're using aspect based display.

You might need to divide or multiply one of those values by "getAspectRatio()" to get a none eliptical orbit.

Crabbages
14
Years of Service
User Offline
Joined: 12th Aug 2010
Location:
Posted: 10th Mar 2012 22:59
Heyyyy yooooou guuuuuys!

Theres a nice little page on using sin and cos here...
http://www.helixsoft.nl/articles/circle/sincos.htm

From editing his example of drawing dots to make up a circle andremembering what you guys said I got this...


Now don't question any of this because I'm afraid it will fall to pieces.

What do you think?
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 10th Mar 2012 23:28
Quote: "What do you think? "

The important thing is if you understand what it's doing.

Quote: "The X and Y defines the middle point of orbit. "

Not quite. The X and Y is where abouts the sprite would be in the circular movement according to the angle. The middle point, according to your code snippet, is what's added to x and y. So in this case, Screenw/2 and Screenh/2 is the middle point.

Quote: "Length is the distance the sprite is away from that point."

That's correct.

The final thing you need to do in your snippet is to actually create the sprite.

Login to post a reply

Server time is: 2024-11-23 05:05:36
Your offset time is: 2024-11-23 05:05:36