Circular/Ellipse Movement in Gamesalad

ADSentertainmentADSentertainment Member Posts: 397
edited March 2013 in Working with GS (Mac)
I've been trying to get an actor to move in an ellipse, I have been able to do it, but I want to see if I can make it so that under a certain condition, the actor will pause and stop moving. and then resume it's movement after a set amount of time. however, after doing this, the actor kinda shifts and doesn't seem to resume in a very smooth way, like it just jumps to a specific point. It might be because I don't understand the equation completely because I'm a bit new to trigonometry. Here's what I did:

Constrain Attribute: self.Position.X To 180*cos( self.Time * self.Speed %360-35)+240

Constrain Attribute: self.Position.Y To 10*sin( self.Time * self.Speed %360-35)+220

Self.Time is 100. I tried making it so that under specific conditions (I don't think they matter) self.speed will be 0 and then after 10 seconds it would change back to 100. I thought it altered the speed after playing around with the equation a bit. but I think it does something else. Could someone please explain the equation so I can see what I did wrong? Thank you!

Having trouble with your game? Sounds like a personal problem.

Comments

  • master200012master200012 Member Posts: 372
    I'm going to guess that your error is caused by self.time. I don't think self.time can be changed; it's automatically done by gamesalad. Make a new attribute called Timer2. Use domenius's timer to say that every .05 seconds or so, change Timer2 to Timer2+.05 . Use Timer2 now instead of self.Time.

    For a diagnosis, because self.time is constantly changing, when you change self.speed to 0, the expression became the sin(-35). When it became 100 again, the expression made sense again, so it jumped to the position it was supposed to.

    Hope this helps! :D
  • SocksSocks London, UK.Member Posts: 12,822
    I've been trying to get an actor to move in an ellipse, I have been able to do it, but I want to see if I can make it so that under a certain condition, the actor will pause and stop moving. and then resume it's movement after a set amount of time. however, after doing this, the actor kinda shifts and doesn't seem to resume in a very smooth way, like it just jumps to a specific point. It might be because I don't understand the equation completely because I'm a bit new to trigonometry. Here's what I did:

    Constrain Attribute: self.Position.X To 180*cos( self.Time * self.Speed %360-35)+240

    Constrain Attribute: self.Position.Y To 10*sin( self.Time * self.Speed %360-35)+220

    Self.Time is 100. I tried making it so that under specific conditions (I don't think they matter) self.speed will be 0 and then after 10 seconds it would change back to 100. I thought it altered the speed after playing around with the equation a bit. but I think it does something else. Could someone please explain the equation so I can see what I did wrong? Thank you!
    You could just replace the self.time and self.speed with an interpolating value. Not sure what you are using the %360 or the '-35' for ?

    I can explain the equation to you but I'm away from my computer right now, but I can do it when I get a chance later . . . .
  • ADSentertainmentADSentertainment Member Posts: 397
    I'm going to guess that your error is caused by self.time. I don't think self.time can be changed; it's automatically done by gamesalad. Make a new attribute called Timer2. Use domenius's timer to say that every .05 seconds or so, change Timer2 to Timer2+.05 . Use Timer2 now instead of self.Time.

    For a diagnosis, because self.time is constantly changing, when you change self.speed to 0, the expression became the sin(-35). When it became 100 again, the expression made sense again, so it jumped to the position it was supposed to.

    Hope this helps! :D
    So since self.time is constantly accumulating, and justifies part of the actor's movement since self.time in the equation. If the actor pauses, the timer still accumulates, so when the actor moves again, it goes to a specific position based on what the timer would be at that time?

    Having trouble with your game? Sounds like a personal problem.

  • SocksSocks London, UK.Member Posts: 12,822
    @ADSentertainment

    Here's a quick demo, click and hold the mouse button anywhere in the scene to trace out an ellipse, let go of the mouse button to pause, re-pressing the mouse button continues the ellipse from where you left off:

    http://www.mediafire.com/?d0d588176zyhv45

  • ADSentertainmentADSentertainment Member Posts: 397
    @ADSentertainment

    Here's a quick demo, click and hold the mouse button anywhere in the scene to trace out an ellipse, let go of the mouse button to pause, re-pressing the mouse button continues the ellipse from where you left off:

    http://www.mediafire.com/?d0d588176zyhv45

    PERFECT. That's just what I needed. Thank you!

    Having trouble with your game? Sounds like a personal problem.

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2013
    Could someone please explain the equation so I can see what I did wrong? Thank you!
    @ADSentertainment

    Constrain Attribute: self.Position.X To 180*cos( self.Time * self.Speed %360-35)+240

    180*cos( self.Time * self.Speed %360-35)+240

    Cos(X) is the cosine of the angle X. If you use self.time as the angle then the angle is constantly increasing and 'cos' is constantly going from +1 to -1 to +1 (and so on) - also I never quite know why people stick %360 in here as there is no need to keep resetting the angle back to 0° when it hits 360 (maybe I'm missing something obvious).

    180*cos( self.Time * self.Speed %360-35)+240

    The 180* part is simply multiplying this value, so +1 to -1 to +1 (and so on) . . .becomes +180 to -180 to +180 (and so on).

    180*cos( self.Time * self.Speed %360-35)+240

    The multiplier 'self.Speed' here will simply multiply 'self.time' (which we are using as the angle), if we just use self.time for our angle without multiplying it in some way it will count up in good old fashioned seconds (which cos will read as degrees) so it will take 6 minutes for a 360 degree complete circle as we will have to wait for 360 seconds to elapse, most people use cos and sin for circles and stuff like that and they generally want them to loop or otherwise complete in time frames much much lower than 6 minutes ! So, using self.time as your angle is too slow for most things, so we multiply self.time to make it faster.

    180*cos( self.Time * self.Speed %360-35)+240

    The '-35' simply adds a fixed offset to the angle cos is being used on. This has no effect on the speed of the rotation (if that's what we are doing here) it just alters our position in the rotation (or more correctly: alters the phase of cos).

    180*cos( self.Time * self.Speed %360-35)+240

    And the '+240' is simply adding a value onto the whole equation, so whatever number [180*cos( self.Time * self.Speed %360-35)] generates we will throw 240 onto it and your actor will be 240 pixels further to the right.


    Hope some of that makes sense ! (Hope some of it is right !)
  • SocksSocks London, UK.Member Posts: 12,822
    @ADSentertainment

    Here's a quick demo, click and hold the mouse button anywhere in the scene to trace out an ellipse, let go of the mouse button to pause, re-pressing the mouse button continues the ellipse from where you left off:

    http://www.mediafire.com/?d0d588176zyhv45

    PERFECT. That's just what I needed. Thank you!

    Cool ! :)
  • ADSentertainmentADSentertainment Member Posts: 397
    Could someone please explain the equation so I can see what I did wrong? Thank you!
    @ADSentertainment

    Constrain Attribute: self.Position.X To 180*cos( self.Time * self.Speed %360-35)+240

    180*cos( self.Time * self.Speed %360-35)+240

    Cos(X) is the cosine of the angle X. If you use self.time as the angle then the angle is constantly increasing and 'cos' is constantly going from +1 to -1 to +1 (and so on) - also I never quite know why people stick %360 in here as there is no need to keep resetting the angle back to 0° when it hits 360 (maybe I'm missing something obvious).

    180*cos( self.Time * self.Speed %360-35)+240

    The 180* part is simply multiplying this value, so +1 to -1 to +1 (and so on) . . .becomes +180 to -180 to +180 (and so on).

    180*cos( self.Time * self.Speed %360-35)+240

    The multiplier 'self.Speed' here will simply multiply 'self.time' (which we are using as the angle), if we just use self.time for our angle without multiplying it in some way it will count up in good old fashioned seconds (which cos will read as degrees) so it will take 6 minutes for a 360 degree complete circle as we will have to wait for 360 seconds to elapse, most people use cos and sin for circles and stuff like that and they generally want them to loop or otherwise complete in time frames much much lower than 6 minutes ! So, using self.time as your angle is too slow for most things, so we multiply self.time to make it faster.

    180*cos( self.Time * self.Speed %360-35)+240

    The '-35' simply adds a fixed offset to the angle cos is being used on. This has no effect on the speed of the rotation (if that's what we are doing here) it just alters our position in the rotation (or more correctly: alters the phase of cos).

    180*cos( self.Time * self.Speed %360-35)+240

    And the '+240' is simply adding a value onto the whole equation, so whatever number [180*cos( self.Time * self.Speed %360-35)] generates we will throw 240 onto it and your actor will be 240 pixels further to the right.


    Hope some of that makes sense ! (Hope some of it is right !)
    Thank you! I think it makes more sense now

    Having trouble with your game? Sounds like a personal problem.

  • LoadedLoaded Member Posts: 240
    @Socks you are a legend mate, thanks :)

    Website » Twitter » Facebook » Loaded Arts - Fun for thumbs.

    Developer Blog » 08/01/2015 - Week 72 – Apple, the great dictator…

  • SocksSocks London, UK.Member Posts: 12,822
    @Socks you are a legend mate, thanks :)

    Cheers big ears !


    : )
  • ja.hernandez@ecisd.usja.hernandez@ecisd.us Member, PRO Posts: 2

    I know this was an old post but I was wondering, using Sock's method, how can I start the actor at the bottom of the screen instead of to the right? I need the actor to move in a vertical ellipse movement (portrait mode).

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2017

    @ja.hernandez@ecisd.us said:
    I know this was an old post but I was wondering, using Sock's method, how can I start the actor at the bottom of the screen instead of to the right? I need the actor to move in a vertical ellipse movement (portrait mode).

    The bottom of a circle is 270° (or -90°), so all you need to do is to add an offset.

    Constrain . . .
    X To Width_Of_Ellipse*cos(angle+OFFSET)+Xcentre
    Y To Height_Of_Ellipse*sin(angle+OFFSET)+Ycentre

    So in this case the offset would be -90° . . . .

    Constrain . . .
    X To Width_Of_Ellipse*cos(angle-90)+Xcentre
    Y To Height_Of_Ellipse*sin(angle-90)+Ycentre

  • ja.hernandez@ecisd.usja.hernandez@ecisd.us Member, PRO Posts: 2

    @Socks said:

    @ja.hernandez@ecisd.us said:
    I know this was an old post but I was wondering, using Sock's method, how can I start the actor at the bottom of the screen instead of to the right? I need the actor to move in a vertical ellipse movement (portrait mode).

    The bottom of a circle is 270° (or -90°), so all you need to do is to add an offset.

    Constrain . . .
    X To Width_Of_Ellipse*cos(angle+OFFSET)+Xcentre
    Y To Height_Of_Ellipse*sin(angle+OFFSET)+Ycentre

    So in this case the offset would be -90° . . . .

    Constrain . . .
    X To Width_Of_Ellipse*cos(angle-90)+Xcentre
    Y To Height_Of_Ellipse*sin(angle-90)+Ycentre

    Works perfectly! Thank you very much.

Sign In or Register to comment.