Actors moving in a circle issue - help please?
JCFord
Member Posts: 785
I have been following the wonderful example on this site to make the Actors go round in a circle which works great: http://gamesalad.com/wiki/how_tos:gsc_circular_movement
EXAMPLE:
CONSTRAIN ATTRIBUTE:
self.position.X... 75*cos( self.Time *600%360)+240
self.position.Y... 75*sin( self.Time *600%360)+160
My question is that I have several actors that I want to move around the same circle and although the formula allows me to change each actors diametre from the circle centre and change the speed at which they move, they all appear to start at the same degree, so at first they all look like they are in a line.
How can I change the degree at which they start around the circle so they all start from various points around it and not in a line?
EXAMPLE:
CONSTRAIN ATTRIBUTE:
self.position.X... 75*cos( self.Time *600%360)+240
self.position.Y... 75*sin( self.Time *600%360)+160
My question is that I have several actors that I want to move around the same circle and although the formula allows me to change each actors diametre from the circle centre and change the speed at which they move, they all appear to start at the same degree, so at first they all look like they are in a line.
How can I change the degree at which they start around the circle so they all start from various points around it and not in a line?
Comments
One of my projects already in progress!
circular motion in physics: a=v^2/r
Each item that is circling for me is a certain degree offset around a circle. So for say five items circling equidistant (in degrees) around a point, each item circling would be given an offset of 360/5 more than the previous item (thusly 0, 72, 144, 216, 288). I store this in an actor attribute called "InitialRotation".
Then I use, in addition to the sin/cos stuff you mention above, a "rotate to angle" in the actor that rotates it to (self.InitialRotation%180)+(whatever is driving your rotation). Have the speed for this real fast! You may have to play around with offsets around the circle but what I am telling you is working for me. I am not driving off of the timer. Since you are, it would probably look something like:
(self.InitialRotation%180)+(self.Time*600%360)
I did just notice my sin/cos operations include the "InitialRotation" being added to the driving piece, which I think for your example would equate to:
self.position.X... 75*cos( self.Time *600%360 + self.InitialRotation)+240
self.position.Y... 75*sin( self.Time *600%360 + self.InitialRotation)+160
It works but I kind of stumbled onto it playing around with things. I was last in Trigonometry decades ago. :-) I've got it working for 4 items, 8 items, and 10 items circling equidistant (in degrees) around a point so I know it works as long as you have the "InitialRotation" angles set for each item appropriately like in my example for 5 items above.
Sorry if I am rambling. It's 4am here. In retrospect, I maybe should be calling the "InitialRotation" attribute something like "InitialRotationOffset".
Finally, you may need to then play with your distance value (the "75" in your sin/cos expressions) and/or the sizes of your items to get them spaced apart from each other appropriately depending on what effect you are trying to obtain.