Player movement is the core mechanic of most games. It allows the player to control a character or object using keyboard, mouse, or touch input. Unity provides multiple ways to handle movement, each suited for different game types.
Movement Methods in Unity
Method 1: Transform.Translate
This method directly changes the object's position every frame. It does not use physics, so collisions won't work automatically.
Example:
using UnityEngine;
public class SimpleMovement : MonoBehaviour
{
public float speed = 5f;
void Update()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(horizontal, vertical, 0);
transform.Translate(movement * speed * Time.deltaTime);
}
}
Output:

- No Rigidbody required
- Use Time.deltaTime for frame-rate independent movement
- Best for 2D games and projectiles
Method 2: Rigidbody.velocity
This method uses Unity's physics system. The object will collide with walls and respond to other physics objects.
Example:
using UnityEngine;
public class PhysicsMovement : MonoBehaviour
{
public float speed = 5f;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(horizontal, 0, vertical);
rb.velocity = movement * speed;
}
}
Output:

- Requires Rigidbody component
- Use FixedUpdate() instead of Update()
- Objects will stop when hitting walls
2D Movement
For 2D games, replace Rigidbody with Rigidbody2D:
Example:
using UnityEngine;
public class Player2D : MonoBehaviour
{
public float speed = 5f;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
rb.velocity = new Vector2(horizontal, vertical) * speed;
}
}
Output:

Input Axes
- "Horizontal": Returns -1 (left/A), 0 (idle), 1 (right/D)
- "Vertical": Returns -1 (down/S), 0 (idle), 1 (up/W)
Key Points to Remember
- Transform.Translate + Update: Simple movement, no physics
- Rigidbody.velocity + FixedUpdate: Physics movement, instant response
- Rigidbody.AddForce + FixedUpdate: Physics movement, gradual acceleration
- Always use Time.deltaTime with Translate movement
- Always use FixedUpdate when working with Rigidbody