Modifying Self.Time or other options

TosanuTosanu Member, PRO Posts: 388

I'm working on a type of creature that has an up and down motion controlled by a sine curve using the self.time function. However, this creature also needs to be able to freeze at times. but when I set that up, once it starts moving, it pops immediately to a different altitude because of the sine function. Is there a way to stop the self.time or modify it so that it will start up again at the same place it stopped?

Comments

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

    You can not modify or pause built-in time attributes (game.Time, scene.Time, self.Time). You'll need to use a custom timer. One way to do this is to have an every 0.1 seconds timer that changes attribute self.timer to self.timer+0.1. Wrap the timer in a rule and give it a condition (e.g. boolean) that you can change to disable the timer when needed.

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

  • TosanuTosanu Member, PRO Posts: 388

    Thanks, that did it.

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

    @Tosanu‌
    @tatiang‌

    You could also do it without timers by simply passing the current time (which is the angle) the sine function is operating on (at the point when it is stopped) over to an attribute - and then measure the difference between this value and the current time (which will continue on - even though the actor is stopped) - then when you release the actor from your Salady grip you just need to subtract this difference from the time the sine function operates on.

    you'll then just need to accumulate these differences, so the value (angle) the sine is operating on always takes into account the total time it was stopped.

    Hope that makes sense, ok, it doesn't make sense to me and I wrote it, so demo time I think . . . . back in a minute or two . . .

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

    Here you go, click on the actor to stop it, let go to let it continue. . . . . .

    Link: https://www.mediafire.com/?7o1brstd92s77i1

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

    Actually you can do it more simply with just a couple of attributes, like this:

    When the actor is stopped,

    Store self.Time - self.Difference (currently set to 0) in an attribute called self.when was I clicked.

    Then constrain self.Difference to self.time-self.when I was clicked.

    Then when the actor is going again,

    Constrain its Y position to Range * sin(( self.Time - self.Difference ) * speed)+offset

    ...

    New Improved Version !! Link: https://www.mediafire.com/?jvc1n0w0623qgj7

    ...

Sign In or Register to comment.