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 :)

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012
    Constrain Y position to: AAA*cos(game.Time *BBB)+CCC

    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)
  • DuendeArkanoDuendeArkano Member Posts: 52
    wow... this kinds of tricks are magic for me, THANKS A LOT!!!!

    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!!!!! :D
  • DuendeArkanoDuendeArkano Member Posts: 52
    At this moment when my actor jump over the plaform, as soon as the platform arrives to the top, the actor go down through the platform, any idea whats happening?
  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012
    by the way, how do you find the 220
    AAA = range of movement from the centre point.
    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).

    image
  • SocksSocks London, UK.Member Posts: 12,822
    At this moment when my actor jump over the plaform, as soon as the platform arrives to the top, the actor go down through the platform, any idea whats happening?
    I have no idea, I don't know anything about your game, how the actors are made, how they are controlled, what's controlling them and so on . . .

    Here's a very quick and messy demonstration of sin controlling some platforms.

    http://www.mediafire.com/?2f60j8e5g0ywdcb
  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012
    Whoops D/P
  • DuendeArkanoDuendeArkano Member Posts: 52
    Absolutely brilliant answer :_D


    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 :D

    I'll try to figure out what happens with my platform, sure its simple thing.


    Thanks a lot again Socks! :D
  • DuendeArkanoDuendeArkano Member Posts: 52
    and thanks for the example!!! sure it solves my two problems! ;DDDDD
Sign In or Register to comment.