Moving platforms
Zilla
Member Posts: 157
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...
I am moving them with a timer that changes their y-position but maybe there is a better way...
Comments
Make its direction 90, and its speed equal to the gravity - that SHOULD counteract it.
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
Thank you very much! I will try this approach in my game
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..
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
-----------------------------------------------
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?)
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...
Silly me! I completely forgot.
I'm nearly done my first game, so this will help in the future
Some don't. Change Attribute for example. That only fires once.