Use interpolate to make animation occurs problem

WeiyuWeiyu Member Posts: 216
edited June 2017 in Working with GS (Mac)

Hello everyone!
I have a problem about interpolate.

I usually use interpolate to make animation.
For example: A actor move up and down.
But always occurs bug?

I made a button to control the actor to move to Position.A(100) and Position.B(-150).
And the actor will move up and down when it position=100.
But when I touch the button again, it sometimes can't back.
Sometimes working, but sometimes not.

Please help me. :'(
What should I do?

↓↓↓There is my GS behaviors and Gif.↓↓↓


Button
When Touch
Do Change Attribute A.Boolean = not(A.Boolean)

Actor
When A.Boolean = true
Do interpolate self.position.y = 100 / 0.25s
Else interpolate self.position.y = -150 / 0.25s

When self.position.y = 100
Do interpolate self.position.y = 150 / 0.25s
//this behavior is move up.(cycle)

When self.position.y = 150
Do interpolate self.position.y = 100 / 0.25s
//this behavior is move down.(cycle)

Comments

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @Weiyu

    • You have a "-" here "Else interpolate self.position.y = -150 / 0.25s"

    • When testing for a position, use "<=" and ">=". If you only use "=" to test for a specific position, then the Rule will usually miss that specific value, because the actor X and Y position is a real number (e.g. 150.5342) and because the actor may be moving to fast.

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

    @Hopscotch said:
    @Weiyu

    • You have a "-" here "Else interpolate self.position.y = -150 / 0.25s"

    This is why typing out your code is often a pointless exercise, if you've made a mistake in your code (an extra comma in an expression, a rule accidentally switched off . . .etc), then who is to say you will not unknowingly auto-correct when typing it out, or who is to say you won't also make another separate/new mistake in your typed code !?

    A screenshot will show us what the code is doing, everything else is subject to transcription errors of various kinds.

    @Hopscotch said:

    • When testing for a position, use "<=" and ">=". If you only use "=" to test for a specific position, then the Rule will usually miss that specific value, because the actor X and Y position is a real number (e.g. 150.5342) and because the actor may be moving to fast.

    I'm not sure that applies to the Interpolate behaviour, Interpolate will always hit the target number - that's why it uses a duration value rather than a pps value like other behaviours like Move.

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @Socks said:

    @Hopscotch said:

    • When testing for a position, use "<=" and ">=". If you only use "=" to test for a specific position, then the Rule will usually miss that specific value, because the actor X and Y position is a real number (e.g. 150.5342) and because the actor may be moving to fast.

    That is why I said "when testing", implying rules. Guess I need to be more clear.

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

    @Hopscotch said:
    That is why I said "when testing", implying rules. Guess I need to be more clear.

    Yeah, that's what I'm saying, even for rules when using an Interpolate ! :)

    With an Interpolated actor targeting X=156, you can quite safely use when X = 156, as Interpolate will always land on exactly 156.

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @Socks said:

    @Hopscotch said:
    That is why I said "when testing", implying rules. Guess I need to be more clear.

    Yeah, that's what I'm saying, even for rules when using an Interpolate ! :)

    With an Interpolated actor targeting X=156, you can quite safely use when X = 156, as Interpolate will always land on exactly 156.

    Quite right, fair point.

  • WeiyuWeiyu Member Posts: 216

    @Hopscotch @Socks

    Thanks for your help, you do gave me a big favor. :D

Sign In or Register to comment.