how to make an object orbit another without rotating

aracknoraracknor Member Posts: 54
edited November -1 in Working with GS (Mac)
Ok let me explain that better. Let say that I have a planet and I put a rocket to orbit that planet. How can i make the rocket keep pointing that planet while it moves around the planet.Like the moon that is orbiting the Earth but we always see the same side.

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,577
    Hi aracknor, a relatively straightforward way I've thought off, which doesn't involve any complicated expressions, is the following (this is untested and seems to work "in my head" so whether it'd work for real, not 100% sure):

    The following explanation is assuming that the rocket is your player, and before it starts orbiting, it's user controlled. The only other thing is that this way it'd be difficult to make any sort of shooting at the planet, although possible + any collision with the rocketwould be out of the question, I think). Edit: you'd have to constrain another actor with the rocket image for coliision...)

    OK, first the orbiting bit: so you've got your planet actor; assuming you use Photoshop or similar, make a new file, square, place your planet image in the centre. Then on another transparent layer, point your ship to the planet. then hide or delete the planet layer.

    When you've imported and placed it in position, with the planet in the same position relative to the rocket as the one in Photoshop, you then use Rotate, with a timer perhaps, on the rocket. As rotate will rotate it from its centre, the rocket should then do what you're asking.

    The only other thing to consider is when the user moves the rocket (assuming this happens) into position where it's to orbit, you'll need a few more rules scripting to rotate this rocket to the point where the player as rocket enters the orbit. This probably will involve some math(s) which unfortunately I can't help you with in this situation.

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • jstrahanjstrahan Member Posts: 498
    SAY YOUR EARTH ACTOR IS 64X64 PIXELS YOU COULD MAKE THE ROCKET 128X128 AND DRAW THE ROCKET ON ONE SIDE OF CANVAS AND LEAVE THE REST TRANSPARENT THEN CENTER THE TWO ACTORS ON TOP OF EACH OTHER AND ROTATE ROCKET AND IT SHOULD LOOK AS IF IT IS SWINGING AROUND THE PLANET BUT STILL POINTING AT IT THEN IF U NEED IT TO FIRE JUST DESTROY THE ROCKET ACTOR AND SPAWN A DIFFERENT ROCKET ACTOR THAT DOESNT HAVE THE EXTRA TRANSPARENCY SET TO THE ANGLE OF THE FIRST ROCKET ACTOR THAT WAY IT FIRES IN THE RIGHT DIRECTION
    IM SURE THERES A MORE OPTIMIZED WAY BUT THIS WAS QUICK OFF THE TOP OF MY HEAD
  • jstrahanjstrahan Member Posts: 498
    OOPS GOT TIED UP LONGER THEN I THOUGHT GUESS I SHOULD HAVE REFRESHED FIRST
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,577
    Hi jstrahan, why are you shouting? ;-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • aracknoraracknor Member Posts: 54
    Thank you guys but let me explain what i am trying to do a little better.
    Ok I am orbiting the planet, I move up and the rocket move clockwise. Move down and it moves counter-clockwise. The rocket is more like an station that shoots a ball of energy that hit the planet destroy a part, the energy bounce back and the station (like a pad for ping pong bounce back the energy to the planet, destroys another part and we keep going until the planet is entirely gone. but while I am moving clockwise or counter I can not keep the part of the station that is supposed to hit the ball in the same place(pointing to the planet).
  • A3MGA3MG Member Posts: 152
    ROCKET
    self.Position.X = 120*cos(self.Time*100%360)+planetXvalue
    self.Position.Y = 120*sin(self.Time*100%360)+planetYvalue
    self.Rotation = vectorToAngle(planetXvalue-selfPosition.X,planetYvalue-self.PositionY)

    the 120 is the distance from the planet, make it bigger to put rocket further away.
    to make it go faster up the 100 to 200 or more.
    planetXValue and planetYvlaue are the x and y of the planet you want to rotate around.

    I might be able to put up a demo of this tomorrow.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,577
    Hi again;
    aracknor said:
    but while I am moving clockwise or counter I can not keep the part of the station that is supposed to hit the ball in the same place(pointing to the planet).

    My explanation and jstrahan's (which are the same) is the only way to do that, I think, providing there's no firing involved, but now I know that the rocket/station is firing, it won't help....hmm, as I mentioned, there is surely a way to add a bit of math to:

    http://gamesalad.com/wiki/how_tos:gsc_circular_movement

    to keep the nose of the station/rocket pointing towards the planet. So as well as the math used in the above example from the wiki, there needs to be more added to rotate the image...oh, just said that..."writing out loud"; really don't know, sorry.

    I hope another more experienced member can help you out now...

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • aracknoraracknor Member Posts: 54
    A3MG... That was amazing. Thank you so much. It is perfect.
  • aracknoraracknor Member Posts: 54
    Thank you gyroscope and jstrahan and sorry if I did not explain myself good the first time.All this is new to me.
    Thanks again
  • POLYGAMePOLYGAMe Member Posts: 3,470
    A3MG said:
    ROCKET
    self.Position.X = 120*cos(self.Time*100%360)+planetXvalue
    self.Position.Y = 120*sin(self.Time*100%360)+planetYvalue
    self.Rotation = vectorToAngle(planetXvalue-selfPosition.X,planetYvalue-self.PositionY)

    No coding? Game creation for the rest of us? LOL.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,577
    aracknor said:
    Thank you gyroscope and jstrahan and sorry if I did not explain myself good the first time.All this is new to me.
    Thanks again

    No worries; I gave it a go! Glad a solution was found for you.
    POLYGAMe said:
    No coding? Game creation for the rest of us? LOL.

    Impressive!

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • jstrahanjstrahan Member Posts: 498
    Sorry didnt mean to shout so loud wasnt on my puter and wasnt watching what i was typing
  • aracknoraracknor Member Posts: 54
    everybody please now move to my other post my rotation is jumpy... please!
  • jstrahanjstrahan Member Posts: 498
    Need to post the fomula u are using in the other post so people will have an idea of whats going on without having to read this post to find it
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,577
    jstrahan said:
    ...didnt mean to shout so loud...

    Was only teasin' ya! :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • aracknoraracknor Member Posts: 54
    When I press UP it rotates counter-clockwise and if I keep the button pressed it moves normal. If I release the button and then I pressed again it may start in the position it was but sometimes it start in a different position on the rotation. The same happens when I hit Down.

    The formula I am using is:
    (To move counter-clockwise)
    when all conditions are valid
    actor receive event key up
    constrain: self.Position.X to 100*cos(self.Time*300%360)+240
    constrain: self.Position.Y to 100*sin(self.Time*300%360)+160
    constrain: self.Rotation to vectorToAngle(240- self.Position.X , 160- self.Position.Y )

    (To move clockwise)
    when all conditions are valid
    actor receive event key Down
    constrain: self.Position.X to 100*cos(self.Time*-300%360)+240
    constrain: self.Position.Y to 100*sin(self.Time*-300%360)+160
    constrain: self.Rotation to vectorToAngle(240- self.Position.X , 160- self.Position.Y )

    I will be posting this on "My rotation is Jumpy" too. Almost every time I try to hit the ball, the pad appear in another place on the rotation.
    Thanks again.
  • jstrahanjstrahan Member Posts: 498
    yea i know i was just explaining myself
  • rdcuberdcube Member Posts: 361
    I did a sample of this and got the 'jumpiness' as well.
    http://gamesalad.com/game/play/65768
    Hope someone can fix.

    Thx!
  • aracknoraracknor Member Posts: 54
    Hi rdcube
    Thanks for sharing.
    That is not what I am talking about but I went to your orbit sample and I found that if you change the timer (in actor2)from 0.1 to 0.01 that jumpiness disappear.

    What I mean by jumpy is that when I press to move clockwise or counter, sometimes it jumps from one position to the other on the circle is like it teleport let say from 12o'clock to 3o'clock without going thru 1o'clock and 2o'clock.
Sign In or Register to comment.