GameSalad

Circular/Ellipse Movement in Gamesalad

ADSentertainmentADSentertainment Posts: 397Member
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 Posts: 372Member
    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.Posts: 12,725Member

    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 Posts: 397Member

    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.Posts: 12,725Member
    @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 Posts: 397Member
    Socks said:

    @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.Posts: 12,725Member
    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.Posts: 12,725Member

    Socks said:

    @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 Posts: 397Member
    Socks said:

    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 Posts: 240Member
    @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.Posts: 12,725Member
    Loaded said:

    @Socks you are a legend mate, thanks :)


    Cheers big ears !


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

    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.Posts: 12,725Member
    edited April 25

    @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%40ecisd.usja.hernandez@ecisd.us Posts: 2Member, PRO

    @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.