Change Orbit Speed

app_sauceapp_sauce Member, PRO Posts: 206

I am trying to solve a problem I ran into. I want to have an object orbit another object i.e planets. But, I want the player to be able to control the speed at which the moving planet orbits the stationary planet. Its turning out to be difficult. I am orbiting by using

constrain position.x to 100cos(self.timeself.speed)%360 + game.planetX and then the same for y (but with sin)

I set up some rules so that when the mouse button is down the planet moves in fast speed and I change the self.speed to a higher number. When The mouse button is up the speed goes back to normal speed. Where I am having trouble is getting the transition to be smooth when the player changes speeds. If anyone knows how to fix this that would be great!

Thanks

SocializeTwitter , **My Site ** **Play Loop Zen Free **iOS HERE, Google Play HERE

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    edited June 2015

    In these kinds of situations self.time or game.time are not ideal, because of the way they extract the speed of angle change using a multiplier, increasing it is not so bad, but decreasing it will cause problems for reasons I can't be bothered explaining :smile:

    You don't really need the %360 modulus part, I swear on my mother's life that regardless of how many times you move around a circle you will never run out of circle, no need to reset it every revolution !

    The easiest way to achieve this is to dump the self.time (or game.time) and use a controller actor to control the angle that cos/sin are operating on, the obvious choice is an actor that is rotating, if you want the rotation of your planet to go fast, make the controller actor spin fast - same deal for slower.

    I've made you a little demo file (file attached) pressing the mouse button smoothly speeds up the rotation, releasing it smoothly returns it to its normal speed, you can play about with the numbers and change them to what you need - the rate at which the orbit speeds up and slows down and the fast and slow speed limits are controlled by the rule called 'Crisps'.

    The controller is visible on screen, this is just for you to see, in reality it would be shoved off screen or made invisible.

    The logic is:

    Planet:
    Constrain planet's X to radius *cos (Controller's rotation)
    Constrain planet's Y to radius *sin (Controller's rotation)
    Constrain planet's Rotation to (Controller's rotation)

    Controller:
    When mouse is down slowly increase SSS to a set value.
    When mouse is up slowly decrease SSS to a set value.
    Rotate at speed SSS

  • app_sauceapp_sauce Member, PRO Posts: 206

    Thanks again. I need to read up on cos/sin, I never use them but it seems like every demo of yours incorporates them. I guess if all else fails, good old math to the rescue!

    SocializeTwitter , **My Site ** **Play Loop Zen Free **iOS HERE, Google Play HERE

  • SocksSocks London, UK.Member Posts: 12,822
    edited June 2015

    @bktennis12 said:
    Thanks again. I need to read up on cos/sin, I never use them but it seems like every demo of yours incorporates them. I guess if all else fails, good old math to the rescue!

    cos/sin are really basic, draw a circle, draw a line from the centre to the edge at whatever angle you like, cos is the horizontal distance from the centre of the circle to where the tip of the line hits the edge of the circle, sin is the same deal but the vertical distance.

    I've made a handy little visual aid !! :) File attached
    Grab the end point of the line and drag it around, and you get a display of cos and sin changing with the change in angle. Stare at it for hours and you will see what's going on.

    The radius of a circle is 1, this is why we multiply it to make it useful (i.e. 100*sin(angle) rather than sin(angle)) - hope that makes sense - not much else to it really.

Sign In or Register to comment.