multiple orbits around a point or object
Alanadale
Member Posts: 6
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
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
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
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.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
The %360 is habit - to keep the angles neat, sry. But helpful when doing debugging.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
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
Yeah, agreed, good if you are debugging, or need the angles to be displayed.
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.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
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.
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
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:
So I was thinking it would break down to:
but I guess it is actually:
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!
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.
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.
Ok that's great to know. I'm sure I'll use this again, so gonna bookmark this conversation. Thank you again Socks.