Sweet home of Wituz
Stay in touch
  • Home
  • Tutorials
    • GameMaker >
      • Beginner >
        • Create a maze game with levels
        • Create a very simple hit-the-ball game
        • Load/save your game
        • Physics in GameMaker!
      • Intermediate >
        • Create a tower defense game!
        • Split-screen Multiplayer - GameMaker:Studio Tutorial
        • Save and Load Objects using INI files - GameMaker:Studio Tutorial
        • Smooth Camera in GameMaker Using Views
        • Multitouch on devices
    • Unity >
      • Beginner >
        • Create a marble roller game in Unity
        • Make a burning meteor using particle systems in Unity 5
      • Intermediate >
        • Using Character Controllers in Platform Games (Unity 5)
    • Miscellaneous >
      • Make your own "Twitch-Plays" stream
      • Generate a normal map from just one texture
      • Sort your messy folders
      • Modelling a planet in Blender
    • Video tutorials >
      • Make Playstation 1 games
  • Blog
  • Creations
    • Games
    • Apps
  • Contact

Physics GameMaker Tutorial

In this tutorial, we will make a platform game, that works only with physics. Click below, and play with the arrow keys to see what we are going to make:

1. Create a physics room

Create a new room, go to the physics pane, and you'll see these settings. The Y value is the amount of gravity. The power that the room pulls the object down. Adjust it  to about 50, or whatever you'd prefer.
Picture

2. Create 4 sprites

We need the following sprites:
  1. Wall 
  2. Small wall 
  3. Player (as a ball, a perfect circle)
  4. Crate
Picture

3. Create a static wall

Create an object, and check "Uses physics" (1). This will enable physics for the object. I call mine obj_wall. 
We need obj_wall to be static. Therefore, check "Kinematic" (4). 

Kinematic means that it isn't affected by the force of other objects. 
To make it completely static, set the density to 0 (2).

Set the collision shape (3). It tells the physics engine how to handle the object. It's like masks are used for normal objects.
An important thing: Set the collision group to 1, in order to make it collide with other physics objects that has collision group 1 as well.
Picture

4. Duplicate obj_wall to obj_wall_small

Just for fun. You can skip this step if you want. 
Remember to adjust the Collision Shape for the new wall.
Picture

5. The player

Create a new object, and call it something like obj_player. The first thing to do, is to enable physics. Modify the collision shape to a circle, and set the collision group to 1. 
To make the player move from side to side, when you press <Left> and <Right> key, you are going to use this code:
Picture
This will apply a force of -100 to the x-axis of the player, which means it will move to the left. To make it move right, just replace -100 with 100.
The next thing the player should do is to jump. Add a keyboard press event to the up key, and use this code:
Picture
If the place isn't free 1 pixel below the player's y position, then the player should jump with a speed of -100.  - and that's what the code does.
One """very important thing""" is to make the player exhaust blue smoke (just joking, but we will do it anyways, it looks so pretty):
Picture

6. Create the crate

Create a new object, call it something like obj_crate, enable physics, set collision shape, set the density to a little lower than normal, to make it weigh a little less than the player. Instead of making it static, this crate will be dynamic.

7. Make a nice room

Here's my setup, but it's all your choice
Picture

Congratulations, you've made a Physics Platformer game


    Stuck? Write your below problem, i'll help you      (I'll check this every day)

Submit

Now
2018-04-17


I'm back!
http://www.wituz.com/blog/im-back​
  • Home
  • Tutorials
    • GameMaker >
      • Beginner >
        • Create a maze game with levels
        • Create a very simple hit-the-ball game
        • Load/save your game
        • Physics in GameMaker!
      • Intermediate >
        • Create a tower defense game!
        • Split-screen Multiplayer - GameMaker:Studio Tutorial
        • Save and Load Objects using INI files - GameMaker:Studio Tutorial
        • Smooth Camera in GameMaker Using Views
        • Multitouch on devices
    • Unity >
      • Beginner >
        • Create a marble roller game in Unity
        • Make a burning meteor using particle systems in Unity 5
      • Intermediate >
        • Using Character Controllers in Platform Games (Unity 5)
    • Miscellaneous >
      • Make your own "Twitch-Plays" stream
      • Generate a normal map from just one texture
      • Sort your messy folders
      • Modelling a planet in Blender
    • Video tutorials >
      • Make Playstation 1 games
  • Blog
  • Creations
    • Games
    • Apps
  • Contact