Player Movement


Introduction
I am  developing the player movement system for my game "On The Way Back." the aim is to create smooth, grid-based movement similar to classic arcade games while ensuring the player doesn't clip through walls or obstacles. Sincs this player is heavily based on pac-man (almost same, actually) the movement mechaniscs are very similar.

Movement Implementation

The core of my movement system uses vector-based direction controls with collision detection. The player character (represented by the Pac-Man sprite in the scene) can move in four directions using either WASD or arrow keys. Movement is handled through a dedicated PlayerMovement script which:

  1. Processes player input
  2. Checks if the desired movement direction is valid (no walls in the way)
  3. Updates the player position accordingly

One challenge I faced was preventing the player from clipping through walls. I solved this by implementing a raycast system that checks for collisions before allowing movement:

bool CanMove(Vector2 dir){

 Vector2 pos = transform.position;

  RaycastHit2D hit = Physics2D.Raycast(pos, dir, 0.55f, wallLayer);

 return hit.collider == null;

}

I've also included a kind of direction buffering system, which makes navigating through the maze-like level feel more responsive, as players can "pre-turn" before reaching an intersection. If the intended direction is valid, the player immediately changes course:

if (CanMove(nextDirection)) direction = nextDirection;

Testing and Feedback

I had my friend test my players movement, one piece of constructive feedback was that the movement speed might feel a bit too fast for some players (might increase the speed as we pass ieach level?) . I've made the speed adjustable in the Unity Inspector (currently set to 4.0f), which will allow for easy fine-tuning as development progresses.

Next Step

For the coming week, I plan to:

  1. Add character animations that respond to movement direction
  2. Implement player health, set up a lot more of the game logic im still missing
  3. add more obstacles and make them interact with the player.

Conclusion

Getting the player movement right has been a crucial first step in developing "On The Way Back." The current implementation provides a solid foundation that I can build upon as I add more gameplay elements. The grid-based movement with collision detection creates the precise, arcade-like feel I'm aiming for, while the direction buffering system adds a layer of responsiveness that makes the game more enjoyable to play.

Leave a comment

Log in with itch.io to leave a comment.