S
Supercoder
Guest
GM Version: Gamemaker: Studio
Target Platform: All
Download: https://drive.google.com/open?id=0B4HyulaY5yE7RzctT2FWV1NrTE0
Summary:
This tutorial will explain how to set up the basics of a physics world. Getting started was one of the hardest steps for me, and I hope this helps ease the process a bit.
Tutorial:
Step 1:
The first step is to create your sprites. You’ll only need two: a ground sprite and a box sprite. Nothing too fancy
Step 2:
Create a ground object and a box object. Check the “Uses Physics” box on both of them. The only setting you have to change right now is the density of the Ground object. Set it to 0. Setting the density to zero means the object will be solid and unmovable.
You should also press that Modify Collision Shape button and create a “fixture” for your object. This will be used for all physics collisions, and should be as accurate as possible within the constraints (no concave, only 8 points max, etc…)
In the box object, add collision events with the Box and Ground objects. Throw in empty comments so the events aren’t automatically removed.
Step 3:
The next step is the room. Create a room and place the solid ground and movable box tiles however you want. The most important thing to remember is the “physics” tab of the room editor. The "Room is Physics World" box has to be checked for anything to happen. As for the gravity and pixels to meters values, I prefer the gravity at 30 and the pixels to meters at 0.05.
Step 4:
If you run your game right now (go ahead, I’ll wait for you), you’ll notice that the boxes drop and don’t do anything after that. This is where you can add stuff. There are many ways to make things move in the physics world, but I’m going to demonstrate physics_apply_impulse (). In the step event of the box, place this short bit of code:
Now when you run the game you’ll be able to move the boxes around with the space bar.
That’s it! Following these instructions you should be able to set up a basic physics room. The documentation is your friend beyond here. Go through it, test things, and learn!
Target Platform: All
Download: https://drive.google.com/open?id=0B4HyulaY5yE7RzctT2FWV1NrTE0
Summary:
This tutorial will explain how to set up the basics of a physics world. Getting started was one of the hardest steps for me, and I hope this helps ease the process a bit.
Tutorial:
Step 1:
The first step is to create your sprites. You’ll only need two: a ground sprite and a box sprite. Nothing too fancy
Step 2:
Create a ground object and a box object. Check the “Uses Physics” box on both of them. The only setting you have to change right now is the density of the Ground object. Set it to 0. Setting the density to zero means the object will be solid and unmovable.
You should also press that Modify Collision Shape button and create a “fixture” for your object. This will be used for all physics collisions, and should be as accurate as possible within the constraints (no concave, only 8 points max, etc…)
In the box object, add collision events with the Box and Ground objects. Throw in empty comments so the events aren’t automatically removed.
Step 3:
The next step is the room. Create a room and place the solid ground and movable box tiles however you want. The most important thing to remember is the “physics” tab of the room editor. The "Room is Physics World" box has to be checked for anything to happen. As for the gravity and pixels to meters values, I prefer the gravity at 30 and the pixels to meters at 0.05.
Step 4:
If you run your game right now (go ahead, I’ll wait for you), you’ll notice that the boxes drop and don’t do anything after that. This is where you can add stuff. There are many ways to make things move in the physics world, but I’m going to demonstrate physics_apply_impulse (). In the step event of the box, place this short bit of code:
Code:
if keyboard_check_pressed(vk_space)
{
physics_apply_impulse (0,0,0,-1)
}
That’s it! Following these instructions you should be able to set up a basic physics room. The documentation is your friend beyond here. Go through it, test things, and learn!
Last edited by a moderator: