multiple orbits around a point or object

Hi GameSalad community

I am new to GameSalad and this is my first time posting so here goes.
I have watched the tutorial on GSHelper.com about "Orbiting around a point or actor" and found it very helpful.
I was trying to expand on that tutorial by having multiple actors orbiting around a point.
An example would be two earths orbiting the sun at the same pixel distance from the sun but orbiting opposite each other by 180 degrees.

I created the sun actor and the earth actor as on the video put in the right coding and all worked well. I then created a second earth actor but found that when you pushed the play button both earth actors orbited the sun but were superimposed on each other, both starting from the 12 o'clock position as you would expect as i had used the same code for both earths.
What i am asking is, is there a way to change the start position for the earth orbiting the sun. Meaning have one earth actor start orbiting the sun from the 12 o'clock position and the second earth actor start orbiting the sun from the 6 o'clock position, all at the same pixel distance from the sun. And expanding even further have as many as required orbiting the sun at the same pixel distance.

Any advice on this matter or comments about my post would be very much appreciated.

Thanks
Alan G

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Here's a demo (I didn't make it) that shows how to orbit an actor based on its rotation direction. By changing the rotation of the blue actor you can reverse the orbital direction. Maybe that will get you started...

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited January 2014
    is there a way to change the start position for the earth orbiting the sun.
    Using the tutorial you used as a starting point, change the formulas as follows to make the object start at the 90 deg position:

    for the X position: 100*cos((game.time+90)*200%360)+game.SunX
    for the Y position: 100*sin((game.time+90)*200%360)+game.SunY

    Now, since you want multiple planets orbiting the sun, this starting angle should not be hardcoded in individual actors.

    Add an Attribute to your prototype Planet as follows:

    StartingAngle (type Real)

    now change the formulas to:

    for the X position: 100*cos((game.time+StartingAngle)*200%360)+game.SunX
    for the Y position: 100*sin((game.time+StartingAngle)*200%360)+game.SunY

    Once you have dragged the actors onto the scene, you can select each instance and change its Attribute to the desired and individual StartingAngle.

    If you break down the formula, you can see that you can do a similar thing for the DistanceFromSun and RotationSpeed:

    for the X position: DistanceFromSun*cos((game.time+StartingAngle)*RotationSpeed%360)+game.SunX
    for the Y position: DistanceFromSun*sin((game.time+StartingAngle)*RotationSpeed%360)+game.SunY

    The RotationSpeed can also be a negative number to change its travel direction to clockwise.
  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2014
    +1 what Hopscotch said, although I'd dump the %360 part, you don't need it.
  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited January 2014
    @Socks, I appreciate the +1 ... on your turf :\">

    The %360 is habit - to keep the angles neat, sry. But helpful when doing debugging.
  • AlanadaleAlanadale Member Posts: 6
    Thanks Hopscotch and others for your comments.

    It worked a treat and was exactly what i was after. I will carry on playing with the code to see what interesting things happen.

    A question for Hopscotch?
    Just out of curiosity did you already know the answer. Was it experience or did you have to work it out? I ask this question because i am new to gamesalad and wonder what you feel is the best way to approach problems.

    Thanks again
    Alan G
  • SocksSocks London, UK.Member Posts: 12,822
    @Hopscotch
    @Socks, I appreciate the +1 ... on your turf :\">

    The %360 is habit - to keep the angles neat, sry. But helpful when doing debugging.

    Yeah, agreed, good if you are debugging, or need the angles to be displayed.
  • HopscotchHopscotch Member, PRO Posts: 2,782
    I am happy it helped you Alan. I had the answer because I have use it in other ways before.

    Best way to get comfortable with GameSalad is to browse though the wealth of excellent video tutorials by the community (like you are doing), pick topics that interest you and immitate, experiment and expand until you understand it well.

    Force yourself to keep it simple in the beginning, try to get a good understanding of the individual elements which later will come together as a game. Build little prototypes and iterate on them.

    If you you have a good understand of how and why the individual elements work, then you will be in a good position to combine these into a well structured and optimised game.

    Above all, we are making games, so have fun doing it!

    :)

    @Socks, I think I originally learned the above from your proof that peeling an orange in one piece of skin while doing cartwheels on a treadmill would only take one quater revolution. Of course slightly simplified.
  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2014
    @Hopscotch
    @Socks, I think I originally learned the above from your proof that peeling an orange in one piece of skin while doing cartwheels on a treadmill would only take one quater revolution. Of course slightly simplified.
    Ah ! My work on Fermat's Mandarin Conjecture of 1875, I'm glad those 15 lonely years of study were appreciated by someone.
  • KC_GamesKC_Games Member, PRO Posts: 86

    So I am having this same issue and have used some of the examples provided above, but find it to be super glitchy. If I have the StartingAngle at 120 degrees, it works fine. But if I change it to 90, it goes to 0 for StartingAngle. Any ideas why this is the case. I attached an example.

  • KC_GamesKC_Games Member, PRO Posts: 86

    Does anybody have an idea of why this is happening? Its driving me crazy. Just trying to get 4 items to revolve around 1 item at 0, 90, 180, and 270. It works for 3 items at 0,120 and 240.

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

    @DreamsComeTrue said:
    Does anybody have an idea of why this is happening? Its driving me crazy. Just trying to get 4 items to revolve around 1 item at 0, 90, 180, and 270. It works for 3 items at 0,120 and 240.

    You have the angle values the wrong way around.

    You have this:

    Radius * cos ( (angle + offset) * multiplier ) + absolute x

    You should have this:

    Radius * cos ( (angle * multiplier ) + offset) + absolute x

    . . . . . . .

    Mars needs to be:

    66 *cos(( self.Time *200)+90)+ game.sunX

    66 *sin(( self.Time *200)+90)+ game.sunY

  • KC_GamesKC_Games Member, PRO Posts: 86

    Thank you so much Socks! It is working now with your help!

    But I still don't understand why. I was looking at Hopscotch's code above and it says:

    for the X position: 100 * cos((game.time+StartingAngle)200%360)+game.SunX

    for the Y position: 100 * sin((game.time+StartingAngle)
    200%360)+game.SunY

    So I was thinking it would break down to:

    radius * cos((game.time+startingAngle)speed+position.X

    radius * sin((game.time+startingAngle)
    speed+position.Y

    but I guess it is actually:

    radius * cos((game.timespeed)+startingAngle)+position.X

    radius * sin((game.time
    speed)+startingAngle)+position.Y

    Either way, thank you so much for your help. You're always so helpful and have helped me out so many times! I owe you! :D :D :D

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

    @DreamsComeTrue said:
    I was looking at Hopscotch's code above and it says . . .

    I guess that was just an oversight on his part, the basic theory is right, just a couple of the values ended up in the wrong order.

    @DreamsComeTrue said:
    radius * cos((game.time *speed)+startingAngle)+position.X

    Well if we want to be absolutely correct it's actually this:

    radius * cos (angle) + position x

    i.e - everything within the brackets is, collectively, the angle.

    So, game time + multiplier + offset are all used together to generate the angle.

  • KC_GamesKC_Games Member, PRO Posts: 86

    Ok that's great to know. I'm sure I'll use this again, so gonna bookmark this conversation. Thank you again Socks.

Sign In or Register to comment.