Ball follow a wave pattern at constant speed
Mesrits 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
I'm going to tag @Socks here, he is the resident sin/cos master!
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
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
!
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.
It's not just circles I do, I can also cook pasta and ride a bike*
(*not at the same time)
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!
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!
neat !
You are welcome! Hope it works for you.
Thanks!