how to make an object orbit another without rotating
aracknor
Member Posts: 54
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
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
IM SURE THERES A MORE OPTIMIZED WAY BUT THIS WAS QUICK OFF THE TOP OF MY HEAD
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
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).
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.
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
Thanks again
:-)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
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.
http://gamesalad.com/game/play/65768
Hope someone can fix.
Thx!
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.