How to Add Physics to Rooms in GameMaker: Studio
When using physics to create your game in GameMaker: Studio, along with using fixtures on your Objects, you need to set up the Room to accommodate for physics.
There are two properties on the Physics tab of the Room Properties window that you need to learn:
Gravity: Gravity is calculated as a vector (a quantity having direction as well as magnitude, which determines the position of one point in space relative to another) using the X/Y coordinates you input.
The length of the vector indicates the force of gravity, and the direction indicates the direction of pull. So, a vector of X = 1, Y = 1 provides a weak gravity that pulls Objects up and to the right, while a vector of X = 0, Y = 10 creates a strong downward gravity.
Pixels to Meters: GameMaker: Studio uses real-world sizes when computing functions, which means that you need to translate your pixel sizes into meters.
This value controls how that ratio works, with (for example) a value of 0.1 being a ratio of 1 pixel = 10 cm. This value should not be any extreme value, such as 10, because it will cause problems.
The in-software Physics tutorial has a Room for physics already set up. Here is a walk-through how and what you need to do for your own game. To set up the Room for physics, follow these steps:
From the Resource tree, right-click Rooms and then select Create Room.
The Room Properties window appears.
Click the Physics tab, as shown in the figure.
The Physics properties appear in the Room Properties window.The Physics properties in the Room Properties window.
Select the Room Is Physics World check box (refer to the figure).
You just told GameMaker that this Room should use Physics for the Instances of Objects during game play.
In the Physics World Properties section, in the Gravity field for X, leave the default at 0.0.
In the Physics World Properties section, in the Gravity field for Y, type 0.0.
You don’t want gravity in your asteroids game, because it takes place in outer space. If you do want gravity in your game, so that Instances naturally fall down, leave the default setting of 10.0.
In the Pixels to Meters field, leave the default of 0.1000.
Click the green check mark.
The Room Properties window is saved and closed.
The default value for Pixels to Meters works well for this game, but make sure that both the X and Y coordinates for the Gravity vectors are set to 0 (that is, if you’re making a space game and you don’t want gravity to interfere with the player’s ship or the asteroids.)