Simple 2D Player Movement

Ahad L. Amdani
2 min readMay 9, 2021

--

Simple 2D Player Movement with Boundaries

It’s a fairly straight forward affair when you consider the mechanics.

  1. Retrieve the axis you’re interested in and store them in a local variable.
  2. Generate the direction of motion based on these inputs.
  3. Perform a translate upon the game object’s transform with an arbitrary speed value and multiplied by Time.deltaTime to account for frame rate differences.
Tracking Player Movement in 2 dimensions in real time

Technically, this wouldn’t be too different than movement in three dimensions. Though, you might want to control the input retrieval for the third dimension through a single button, to reference a “jump” action for instance, which would gradually spike the game objects position upwards, and then fade it back downwards (due to gravity). Still, so long as you provide a value from -1 to +1 based on said input, you’d achieve the desired effect.

For our 2.5D “over-the-top” arcade style space shooter game, Sovereignty, we will be restricting the area the player can maneuver with simple constraints limiting the translation boundaries available to the transform for the player’s game object leveraging the Mathf.Clamp method:

We’re limiting the bounds to the sides and bottom of the camera’s viewport to just shy of midway up

--

--