0
0
Unityframework~5 mins

Input axis for smooth movement in Unity

Choose your learning style9 modes available
Introduction

Input axis lets your game character move smoothly instead of jumping in steps. It reads how much you press a key or move a joystick.

When you want a character to walk or run smoothly in a game.
When using a joystick or gamepad for gradual movement.
When you want to detect how hard a player is pressing a control.
When you want to move objects in a game with fluid motion.
When you want to create natural-feeling controls for a player.
Syntax
Unity
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");

"Horizontal" and "Vertical" are default input axis names in Unity for left/right and up/down controls.

Input.GetAxis returns a float between -1 and 1, showing how much the control is pressed.

Examples
Reads horizontal input for left/right movement smoothly.
Unity
float moveX = Input.GetAxis("Horizontal");
Reads vertical input for up/down movement smoothly.
Unity
float moveY = Input.GetAxis("Vertical");
Reads horizontal input instantly without smoothing (jumps between -1, 0, 1).
Unity
float moveX = Input.GetAxisRaw("Horizontal");
Sample Program

This script moves a game object smoothly based on keyboard or joystick input. The character moves left/right and forward/back smoothly using Input.GetAxis.

Unity
using UnityEngine;

public class SmoothMovement : MonoBehaviour
{
    public float speed = 5f;

    void Update()
    {
        float moveX = Input.GetAxis("Horizontal");
        float moveZ = Input.GetAxis("Vertical");

        Vector3 move = new Vector3(moveX, 0, moveZ) * speed * Time.deltaTime;
        transform.Translate(move, Space.World);
    }
}
OutputSuccess
Important Notes

Input.GetAxis smooths input over time, so movement feels natural.

Use Input.GetAxisRaw if you want instant input without smoothing.

Always multiply by Time.deltaTime to keep movement smooth and frame-rate independent.

Summary

Input axis reads how much a control is pressed, giving smooth values between -1 and 1.

Use Input.GetAxis for smooth gradual movement in games.

Combine axis input with speed and Time.deltaTime for smooth character movement.