Ball follow a wave pattern at constant speed

Mesrits OperandiMesrits Operandi HollandMember, PRO Posts: 10

Hallo all!

When I make a ball go from left to right in a wave movement up and down. I do the following:

Move:
Direction: 0
At speed of: 100

Constrain attribute:
constrain: self.position.y to 60sin(self.time)150)+160

So far so good... :)

But when I change the speed to, let's say 10, the distance of the wave from left to right also gets smaller.
How do I prevent this from happening?

Goal:
When people press a "slower button" the ball needs to follow the wave on a slower pace, when they press a "faster button" the ball needs to follow the exact same wave but at a faster pace.

I hope that made any sense and thank you very much!

Comments

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
  • pHghostpHghost London, UKMember Posts: 2,342
    edited October 2014

    So, you make the speed 1/10 of the original, you need to reduce the multiplier as well: 150/10 = 15

    So you will have 60*sin(self.time * 15)+160

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

    @Lennart said:
    Goal:
    When people press a "slower button" the ball needs to follow the wave on a slower pace, when they press a "faster button" the ball needs to follow the exact same wave but at a faster pace.

    !

    You need to reduce the speed the angle that sine is operating on by the same ratio you have reduced your Move speed.

    So, if you half the speed of the Move behaviour, you also need to half the speed of the angle change, so this . . . Move 100 / Y= 60 *sin(self.time *150)+160 . . . would become this . . . Move 50 / Y= 60 *sin(self.time *75)+160.

    So if you are reducing your Move speed from 100 to 10, then the speed of the angle change would need to change from 150 to 15.

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

    @jamie_c said:
    I'm going to tag Socks‌ here, he is the resident sin/cos master! :)

    It's not just circles I do, I can also cook pasta and ride a bike*

    (*not at the same time)

  • Mesrits OperandiMesrits Operandi HollandMember, PRO Posts: 10

    You guys are great! Thanks a lot, gonna play with this over the weekend and let you know how it turned out!

    I can cook a descent pasta too! ;)

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

    You can also get the effect you want by using self.Position.X (instead of self.Time)

    60*sin( self.Position.X *1.5)+160

    Attached is an example. (Press and hold the mouse button to go from a move speed of 100 down to 10.)

  • Mesrits OperandiMesrits Operandi HollandMember, PRO Posts: 10

    @RThurman said:
    You can also get the effect you want by using self.Position.X (instead of self.Time)

    60*sin( self.Position.X *1.5)+160

    Attached is an example. (Press and hold the mouse button to go from a move speed of 100 down to 10.)

    Thank you and all for the kind help! The .zip, is really helpful as well!

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

    @RThurman said:
    You can also get the effect you want by using self.Position.X (instead of self.Time)

    60*sin( self.Position.X *1.5)+160

    Attached is an example. (Press and hold the mouse button to go from a move speed of 100 down to 10.)

    neat ! :)

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

    @Lennart said:
    Thank you and all for the kind help! The .zip, is really helpful as well!

    You are welcome! Hope it works for you.

    @Socks said:
    neat ! :)

    Thanks!

Sign In or Register to comment.