Code the Character

The following tutorial will show you how to add code to your character object so a player can make the character move up, down, left and right.

For your own game, you may only need up and down or left and right. Consider how the code would change.

Example Code

The following code example will allow a character to move up, down, left and right.

What happens if move_speed is made lower or higher?

//Sets the movement speed of the Drone to 6
var move_speed = 6; 

//If the W key is pressed, change the Y position of the character by move_speed so the drone moves up.
if (keyboard_check(ord("W"))) y -= move_speed; 

//If the S key is pressed, change the Y position of the character by move_speed so the drone moves down.
if (keyboard_check(ord("S"))) y += move_speed;

//If the A key is pressed, change the X position of the character by move_speed so the drone moves left.
if (keyboard_check(ord("A"))) x -= move_speed;

//If the D key is pressed, change the X position of the character by move_speed so the drone moves right.
if (keyboard_check(ord("D"))) x += move_speed;