Simple 2D Player Movement
--
It’s a fairly straight forward affair when you consider the mechanics.
- Retrieve the axis you’re interested in and store them in a local variable.
- Generate the direction of motion based on these inputs.
- 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.
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: