This guide will walk you through the process of setting up a camera to follow your player character in GameMaker Studio. This is a crucial step for creating a more focused and immersive game experience, especially for larger levels.
Setting Up the Viewport
The viewport is the area of your game room that is visible on the screen. By default, it shows the entire room. We will change this to focus on the player.
- Navigate to your Assets browser and open the room you are working in, typically Room one.
- In the Room Editor, look for the Viewports and Cameras section in the properties panel and make sure to enable the viewports.
- Select Viewport 0 to begin configuring its size and settings.
- Adjust the viewport’s width and height to your desired size. For a retro 8-bit look, the video recommends setting the width to 320 and the height to 180 [00:36].
Configuring Viewport Properties
Once you’ve set the viewport’s dimensions, you need to tell the camera what to follow and how to move.
- Under the Viewport Properties section, adjust the Viewport Size to a larger resolution for a clear display. The video suggests setting the size to 1280 by 720 to maintain the correct proportions [01:13].
- To make the camera follow your player, check the box to enable Object Following.
- From the drop-down menu, select your player object, which should be named
OBJ_player. - Next, set the camera’s horizontal and vertical borders. These values determine how close the player can get to the edge of the screen before the camera starts to move. A good starting point is to set both borders to half the viewport’s size. For a 320×180 viewport, the borders would be 160 (horizontal) and 90 (vertical) [02:01].
Running and Testing the Camera
- With all the settings configured, save your changes and click the Run button to launch your game.
- When the game starts, you should see the viewport focused on your character. As you move your player with the WASD keys, the camera should now smoothly follow their movements, keeping them in the center of the screen [02:23].
Next Steps
Now that you have a functioning viewport and camera, you can continue to enhance your game. The next logical step, as the video mentions, is to add more advanced features, such as character animations that correspond to different directions of movement [03:00]. This will make your player character feel more alive and responsive as you navigate your game world.
A Guide to Setting Up a Viewport and Camera in GameMaker was originally found on Access 2 Learn