Progress Log – Player movement tweaking
This evening I finally got around to redo the way movement input is handled in the game. By this I mean the way the game interprets the information it receives from a gamepad analog stick. The current implementation works, but it could be better.
When you’re playing, the movement feels slippery and imprecise. The control scheme is meant to limit the player to four directions, but in the video below you can see some diagonal movement. This is not what we want.
I wanted to have a control scheme which provided snappy movement, and no diagonal drifting. The player already quickly snaps to face the cardinal direction it’s moving in; I had built that in already. What remained was forcing the player motion to those four directions. It took me a couple of attempts to figure out the best way to achieve this.
In the old version, each axis of the left stick is handled separately, so movement on the X axis can be made at the same time as movement on the Y axis. I soon discovered that this was my problem. I created a system which works out what direction to move in through what is basically a process of elimination. When the analog stick is moved, it starts by reading input from the analog stick, and figures out which axis has a stronger value (eliminating the two directions from the weaker axis). Then it decides on which direction to move in by asking whether the value is positive or negative (eliminating another direction). This leaves the system with only one direction, the one the player will move in.
So now instead of X and Y being handled independently of each other, all movement input has to go through the system above before any actual movement happens on screen.
Much better :). Now I just need to replace that placeholder player model.