Moving platforms

ZillaZilla Member Posts: 157
edited November -1 in Working with GS (Mac)
Does anybody know of an existing GS example that has platforms that move vertically (in a scene with gravity)?

I am moving them with a timer that changes their y-position but maybe there is a better way...

Comments

  • firemaplegamesfiremaplegames Member Posts: 3,211
    first, try applying an Acceleration Behavior to the platform.

    Make its direction 90, and its speed equal to the gravity - that SHOULD counteract it.
  • ZillaZilla Member Posts: 157
    Cool idea, but it does not work. The platform is moving upwards ;)
  • firemaplegamesfiremaplegames Member Posts: 3,211
    right...

    Is Gravity ABSOLUTELY necessary in your game? And what I mean by that, Is EVERYTHING supposed to get affected by gravity? Do you have a complex physics situation going on?

    If only a few things are getting affected by gravity, like let's say a pinball game - where only the balls are affected by gravity, or let's say a mario-type game, where only mario and a few enemies are affected by gravity, i think it is a much better solution to only apply a constant down acceleration to those specific actors.

    gravity is just an acceleration in the down direction. If you turn it on for your scene, EVERY actor gets that force applied to them.

    If it is really only the main character that is affected, and maybe some enemies, I would just apply the gravity to them.

    it makes things like moving platforms MUCH easier to deal with. And things like floating gems, coins, etc.
    much simpler as well.

    You can have things in mid-air without all the hassle of counter-acting gravity all the time.

    Something to think about anyway.

    As far as the vertical moving platform is concerned, if you do need gravity, I think you still will need a constant up acceleration to counteract it, but you will also need to constrain it with some trig functions as well, probably sine or cosine, I'm not sure...

    Joe
  • ZillaZilla Member Posts: 157
    `If it is really only the main character that is affected, and maybe some enemies, I would just apply the gravity to them.`

    Thank you very much! I will try this approach in my game :)
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Cool! Glad I could help!

    Also, I would make the gravity a global game attribute so you can easily change it.

    And you can then easily change it on the fly as well, for things like outer space or underwater scenes. Or a special super-jump power-up etc..
  • butterbeanbutterbean Member Posts: 4,315
    For gravity, you'd make it a global game attribute, would it be real? And how would you originally set it?
  • firemaplegamesfiremaplegames Member Posts: 3,211
    @butterbean: you could make it real or an integer, it doesn't really matter. A real number has decimal places after it, like 450.5, where an integer is just a whole number. It depends how subtle you want to get! It probably is a little better performance-wise to use integers.

    So you create a global integer Attribute called "gravity". Set it to something like 500

    Any actor that you need to react with gravity, simply add an Accelerate Behavior to them like this:

    Accelerate
    Direction: 270, speed: game.gravity
  • @firemaplegames

    -----------------------------------------------
    Any actor that you need to react with gravity, simply add an Accelerate Behavior to them like this:

    Accelerate
    Direction: 270, speed: game.gravity
    ------------------------------------------------

    Would you put this in a timer? And if so, what would the "Every" be? (IE. How many times would we run this a second to replicate gravity?)
  • firemaplegamesfiremaplegames Member Posts: 3,211
    No, I would always apply it. - if that's what the game calls for...

    You don't need a Timer to do that though, simply drag that Behavior to the Actor.

    Some behaviors like Accelerate, Move, Constrain Attribute, Control Camera, etc, will always fire...
  • "If a Behavior is not wrapped in a Rule, it will always fire constantly. "

    Silly me! I completely forgot.

    I'm nearly done my first game, so this will help in the future :)
  • firemaplegamesfiremaplegames Member Posts: 3,211
    I just edited my previous comment... SOME behaviors always fire...

    Some don't. Change Attribute for example. That only fires once.
  • ZillaZilla Member Posts: 157
    How would you implement a JUMPING ACTOR in a scene with gravity turned off?
Sign In or Register to comment.