Better solution for an up-to-down platform?
Hi guys!
Im working on the tipical up-down/left-right platform movement, at this point im doing it using two invisible actor who works as the boundaries for the platform, but im pretty sure that i can do the same without using the invisible actors...
What i have:
Platform moves till collide with ActorBoundariesUP -Then- Goes Down
Platform moves till collide with ActorBoundariesDOWN -Then- Goes Up
And i think there should be a way to do it like that:
Loop: Platform moves to Y:270 and then moves to Y:170
Any idea??
Thanks in advance![:) :)](http://forums.gamesalad.com/plugins/emojiextender/emoji/twitter/smile.png)
Im working on the tipical up-down/left-right platform movement, at this point im doing it using two invisible actor who works as the boundaries for the platform, but im pretty sure that i can do the same without using the invisible actors...
What i have:
Platform moves till collide with ActorBoundariesUP -Then- Goes Down
Platform moves till collide with ActorBoundariesDOWN -Then- Goes Up
And i think there should be a way to do it like that:
Loop: Platform moves to Y:270 and then moves to Y:170
Any idea??
Thanks in advance
![:) :)](http://forums.gamesalad.com/plugins/emojiextender/emoji/twitter/smile.png)
Comments
AAA = range of movement from the centre point.
BBB = speed of platform movement.
CCC = the centre point of the movement.
So using your figures of Y:270 and Y:170 . . .
Constrain Y position to: 50*sin(game.Time *100)+220
(I guessed the speed at 100, change it to whatever you want)
by the way, how do you find the 220?
this 220 its the key to flow between 170 and 270, isn't it?
T-H-A-N-K-S!!!!!
BBB = speed of platform movement.
CCC = the centre point of the movement.
The sin function changes it's value from -1 to +1 over and over again, so we get:
(-1 . . . +1 . . .-1 . . . +1 . . .-1 . . . +1 . . .-1 . . . +1 . . . etc)
If we multiply it by 50 (the '50*sin' or 'AAA' part) we get.
(-50 . . . +50 . . . -50 . . . +50 . . . -50 . . . +50 . . . etc)
So now we have a value that 'moves' through 100 'units' (-50 to +50)
If we used this for our actor's Y position it would start at 0 (the bottom of the screen) go downwards to -50 pixels (which we wouldn't see as it's off the screen), then up to +50 pixels.
So that's not good for us, so we need to add 220 pixels onto the whole calculation (the '+220' or 'CCC' part) so we get:
(170 . . . 270 . . . 170 . . . 270 . . . 170 . . . 270 . . . 170 . . . 270 . . . 170 . . . 270 . . . etc)
(Because -50 + 220 = 170 . . . . . and 50+220 = 270)
Hope that makes sense.
Think of sin like this: (in this example image grabbed off the internet, the value is -5 to +5, so to get this we would need to start our equation with 5*sin).
Here's a very quick and messy demonstration of sin controlling some platforms.
http://www.mediafire.com/?2f60j8e5g0ywdcb
There's a lot i have to learn about gs, thanks a lot*100 for make me understand this a little bit, i understand it perfectly
I'll try to figure out what happens with my platform, sure its simple thing.
Thanks a lot again Socks!