Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Teaching a player how to walk

Author: Sylas Braveheart-Kern

Date: 1/17/2025

 

“So, Game Development, huh? Neat stuff” Is what I would say if it didn’t take me a day to implement basic moving. I mean, I had to spend 15 smackaroos just to get a decent model with animations! Anyways, I guess I’ll do a quick dive on the process it took me. Buckle your seatbelts as we take a deep dive into…Teaching a slime how to walk!

1. Planning and Requirements

Before diving into the good stuff, we need to figure out a gameplan for our movement system. What type of locomotion we going for? Basic locomotion typically involves simple translations (moving a character from one place to another), but there are many variations depending on the type of game we’re creating.

Key Requirements:

  • Movement type: Will it be grid-based, freeform, or physics-driven?
  • Input method: How will the player control movement (e.g., keyboard, mouse, gamepad)?
  • Character abilities: Does the character have running, jumping, or crouching abilities?
  • Environment: Is the movement constrained by terrain, gravity, or other physics elements?

Following these basic parameter will guarantee that not only will you have a character movement that rivals even the heavens above, but you’ll also look like you actually know what you’re doing.

2. Setting Up the Environment

For our example, we’re going with Unreal, and like most 3D engines, you’re gonna need a player character. This includes importing a character model and assigning appropriate animations for the different states like idle, walking, running, and jumping.

For basic testing, you’ll need to:

  • Import the character model and rig it for animation.
  • Set up the animation states (idle, walk, run, jump, etc.) in the animation controller (e.g., Unreal’s AnimBlueprint).
  • Create a simple environment where you can test the locomotion system, ensuring that there’s enough space to observe the player’s movement in action.

3. Coding the Basic Movement

Input Handling

Once the setup is done, give yourself a pat on the back, not only can your machine run Unreal, you’ve navigated most of the screens that’ll confused even the most seasoned of veterans…or something, I don’t know. Anyways, the next step is to handle player input. Whether the game uses a keyboard, mouse, or controller, you’ll need to read input from the user and use that to drive the character’s movement.

In 3D:

  • Input Axis: The typical movement axes (X, Y, and Z) should correspond to left-right, forward-backward, and vertical movements. As for Unreal, and depending on how you set up your player input in the project settings, using AddMovementInput() will make it easy to determine if your character is going forwards or backwards, if you’re doing strafing, the replace EAxis::X with EAxis::Y , and example of it being used for forwards and backwards movement is below:
  • AddMovementInput(FRotationMatrix(GetControlRotation()).GetUnitAxis(EAxis::X), Value);
  • Character Controller: In Unreal, the ACharacter class has a built-in character controller that you can use. When creating your class, search for that class to use as your parent.

Implementing the Movement Logic

Once the input is captured, the next step is applying that input to the character’s position and ensuring smooth movement. The basic code might look something like this:

Example (Unreal C++):

void ACoolCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)


    Super::SetupPlayerInputComponent(PlayerInputComponent); //Always call your parents

    //Aside from basic movement, other things like jumping would be added in here

    PlayerInputComponent->BindAxis("MoveForward", this, &ACoolCharacter::MovingForward);
    PlayerInputComponent->BindAxis("Strafe", this, &ACoolCharacter::Strafing);

}

//Some other functions placed here

void ACoolCharacter::MovingForward(float value)

{

   //AddMovemenentInput takes in a world direction and a scale value.

   //The world direction is calcuated by getting the rotation of the player controller

  //as a FVector (Which is found from singling out which axis to focus on), and scaling it

   //by the value, which comes from the input of the key (pressed or not)

   AddMovementInput::(FRotationMatrix(GetControlRotation()).GetUnitAxis(EAxis::X), value); }

void ACoolCharacter::Strafe(float value)

{

   //Strafing would be done in a similar manner, but instead of looking at the X axis //it would be looking at the Y axis

}

 

4. Closing statements and a challenge

Closing off, I wanted to say that this is probably one of the more simpler parts of game development, but a crucial one. If you don’t know what type of movement you want for your player, then you’ll be shooting yourself in the foot later on when you finally get to play testing your game, especially when you realize that said controls are wonky, and don’t fit the feel of your game. This doubles down for camera controls, and we all know how picky gamers are with camera controls (I’m one of them). Which goes into my challenge for you, we handled character movement, but that still leaves open the camera, and assuming you know how to instantiate a camera and a boomstick (if you’re in a third-person perspective), you still need to allow your players to move around the camera, if that’s what your game intends to have. So, my challenge is to implement basic camera controls, maybe something that feels like the Ratchet and Clank games, if you want specifics. Anyways, that’s all I have for today, or tonight. Have fun, everyone, and don’t forget the pizza you left in the oven, Mark!

 

Support this post

Did you like this post? Tell us

Leave a comment

Log in with your itch.io account to leave a comment.