From the course: Building a Physics-Based Platformer in GameMaker Studio Using GML
Unlock this course with a free trial
Join today to access over 22,400 courses taught by industry experts.
Using Finite State Machines - GameMaker Tutorial
From the course: Building a Physics-Based Platformer in GameMaker Studio Using GML
Using Finite State Machines
- [Instructor] To control for our players movements, we're going to use a well known programming pattern called the finite state machine. Finite state machine is set up using a switch statement. We transition between states based on inputs or events. Our state machine will only execute code that is associated with the given state when we're in that state, and it keeps our code clean and manageable by avoiding nested if statements which can quickly get out of control. This is what the finite state machine for our game will look like. Each one of the circles represents a state and will be a case in our switch statement. The arrows in between the circles are state transitions, and they represent either player inputs, or events that happen in the game. Let's take a look at how it will work. Our player will initialize to the idle state, and the only thing we're allowed to do in that state is press the space bar so that we can start running. Once we're in the running state, we have two…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Create the player object2m 48s
-
Using Finite State Machines1m 38s
-
Player state machine3m 16s
-
Control logic: Idle to run state2m 5s
-
Control logic: Idle and run animations2m 38s
-
Control logic: Jump state3m 50s
-
Control logic: Rotation and animation2m 46s
-
Collision checking with the ground3m 49s
-
Make the player duck3m 57s
-
View following and debug3m 18s
-
Create physics fixtures in code6m 48s
-
Swap fixtures4m 3s
-
-
-
-
-
-