Ramps in platform gamesThe code will replace the standard behaviour with "move_contact" actions that will make the object free fall normally, "land" on solid objects and further to this it will follow ramps of up to 45 degrees up or down. Important note:
It will be up to the developer to add keyboard actions, set a gravity, friction, select sprites etc. As the keyboard handling is separated from the engine it is easy to create "monsters" under computer control.
Jump is required as the ramp code ignores "vspeed" causing the player to stick to the platform even if the platform curves down steeper than freefall. Setting jump to true will "unstick" the player from the platform.
It will be seen that this code "glues" the player to the platform at times when possibly they ought to free-fall. I find the effect can be pleasing though. No extra effort is required to run uphill (yet). A more sophisticated engine would allow for gravity when running up and down. Unlike the simple platform code, here there is separate code for a platform and for freefall.
Note that at this time there is no support for special (non-solid) platforms. It should not be hard to add though, as if the player does not have solid platform under them then the player is assumed to be falling. It should be a simple matter to detect an alternative platform type, either using place_meeting or a collision event. More to follow... Demo: |