In this lesson, you will learn how to translate continuous analog stick values from a controller into smooth, directional movement for your 3D character.
From Joysticks to Vectors
When you push a controller joystick, it doesn’t just send an "on" or "off" signal like a keyboard key. Instead, it provides a Vector2 value where the X and Y coordinates represent the stick's position relative to its center. If you push the stick all the way to the right, you get a value like (1, 0); pushing it halfway up and to the left might give you (-0.5, 0.5).
To move a character, we take this 2D vector from the joystick and map it into 3D space. Since our character stands on the ground, we typically map the joystick’s X input to the character’s "Right" axis and the joystick’s Y input to the character’s "Forward" axis.
Implementing the Movement
Once you have the Vector2 input from your Action Map, you calculate the final movement direction by multiplying these inputs by the character's forward and right vectors.
// Assuming 'inputVector' is your Vector2 from the controller
Vector3 moveDirection = (transform.right * inputVector.x) + (transform.forward * inputVector.y);
// Apply the movement to your character
controller.Move(moveDirection * speed * Time.deltaTime);
By using the character’s transform.right and transform.forward directions, the movement remains intuitive—"up" on the joystick always moves the character forward relative to where they are currently facing, rather than toward a fixed point in the world. Because the joystick provides continuous values, multiplying these by your speed variable creates the smooth, gradual acceleration and deceleration expected in modern 3D movement.
Remember that since the joystick can return a magnitude less than 1.0 (when tilted only slightly), your character will naturally move slower when the stick is pushed gently and reach full speed when pushed to its limit, creating a fluid locomotion experience.
Key Takeaway: Mapping joystick input involves converting a 2D analog vector into 3D world space using your character’s current forward and right orientation to ensure movement is intuitive and proportional to the stick's tilt.