We are searching data for your request:
First of all, open the objects tab and select your main character (sprite). Add a step event so you can add actions to the sprite so it will move in a platform-like fashion.
Go to the side tab marked Control, add the action Check Empty, and set "y" to 1. Also, check the Relative box.
Next, set the gravity and set the direction to 270. That action can be found in the tab labeled Move. Don't forget to add an else event. Else can be found in control. This creates an if statement.
After adding the Else event, set both the gravity and the direction to 0. This will allow the game to understand that when it's collision free, there is a certain amount of gravity so you can jump.
Add a Key Press event. Select it so it's Up. After that, add a check collision event and set "y" to 1. The event should be relative. The action can be found under Control.
Since you are dealing with gravity, vertical speed is important! Depending on the game you want to make set the vertical speed. My vertical speed is -5. This action is under Move.
If you haven't created a collision event with an object wall (objWall), do so. The Move to Contact action is under Move. Set the direction to direction and the maximum to 12 against solid objects.
Don't forget to add a small piece of code! Type in : move_speed=5; This will allow you to move at a speed of 5 everywhere you go.
If you have the events: Key release Up, Down, Right Left, Keyboard Up or Down, please delete them. If you keep them, it won't look like a game with gravity, the sprite will seem to be in a maze game.
The next step is to put -move_speed as x and to check it as relative. This will allow you to move left relative to if there is a collision.
Next, add a Jump to Position action. It is found under the Move tab. make x -move_speed and make it relative. This will allow the sprite to move back and forth.
Do the same to the keyboard right action except instead of -move_speed, its move_speed. This would help move the sprite back and forth to jump.
Enjoy your GameMaker game with gravity! :)