Non-Linear Movements

supafly129supafly129 Member Posts: 454
edited November 2014 in Working with GS (Mac)

I'm interested in implementing some unique movements for actors, and attached is an example of a circular movement I'd like to use.

The problem is that when I pause this movement and then unpause it with a custom rule, the actor does not continue from where it left off, and instead the actor restarts itself from its starting X,Y coordinates. Is anyone savvy enough with sin/cos formulas to see how I might get this to work? This would be really helpful for creating smooth non-linear movements that can be interrupted/restarted correctly.

Thanks!

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @Socks is our trig guru. He will likely have a suggestion for you.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    That formula is using game.time as the counter. But when you pause, game.Time just keeps going. When you unpause, it starts using game.Time again but time has moved on. Thus it jumps to where game.Time currently is.

    Just replace "game.Time" with your own counter attribute. Something like this:

    When game.pause is false
      Constrain Attribute: self.myCounter To: self.myCounter + 1
      Constrain Attribute: self.Position.X To: cos(self.myCounter*5)*60+self.Init X
      Constrain Attribute: self.Position.Y To: sin(self.myCounter*5)*60+self.Init Y
    
  • SocksSocks London, UK.Member Posts: 12,822

    @tatiang said:
    Socks is our trig guru. He will likely have a suggestion for you.

    AAA * BBB * CCC

    Just shuffle that around and you will eventually end up with a picture of a cat or a planet or something. :)

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

    @RThurman said:
    That formula is using game.time as the counter. But when you pause, game.Time just keeps going. When you unpause, it starts using game.Time again but time has moved on. Thus it jumps to where game.Time currently is.

    Just replace "game.Time" with your own counter attribute. Something like this:

    When game.pause is false
      Constrain Attribute: self.myCounter To: self.myCounter + 1
      Constrain Attribute: self.Position.X To: cos(self.myCounter*5)*60+self.Init X
      Constrain Attribute: self.Position.Y To: sin(self.myCounter*5)*60+self.Init Y
    

    Yep, that's the way I see the question too, it's not actually a trig / sin-cos question at all, it's a timer / offset thing.

    I've done similar stuff in the past and have started a time offset counting at the point of the project being paused - and then when the project restarts the angle that sin/cos is working on has that offset thrown into the mix (basically game.time - offset).

    It's a lot simpler than I've made it sound !

  • supafly129supafly129 Member Posts: 454

    @Socks‌ @RThurman‌ @tatiang‌ thanks for your input! This was really helpful and works perfectly B)

Sign In or Register to comment.