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.

Make the player duck

Make the player duck

- [Instructor] The next thing we want to do is make our player duck when we press the down arrow, stop ducking when we release the down arrow, and we also want to enable our player to jump from the duck state. So let's get that going. Let's first create a couple scripts. I'll go to the script folder, and say Create Script, and we'll use this script to check for the down arrow being pressed, and move our player into the duck state. So I'll call it sc for script, underscore duck. I'll give it a comment, call it ducking, and we say if, we'll check for a keyboard press. And here we want to check for the down arrow, so we'll use vk_down. That's GameMaker's built-in variable for the down arrow key. A couple brackets, and since we're using our state machine architecture, we simply have to take our current state variable, and change it to our new state variable of ps.duck. We can also take this opportunity to set the sprite index, so let's take our current sprite_index, and set it to our…

Contents