A basic character controller for a 2d character in Unity.
This project features a responsive character controller that prototypes core mechanics for an upcoming 2.5D platformer. It also showcases a custom 3D-to-2D asset pipeline, converting rigged Blender animations into optimized Unity spritesheets to streamline workflow.
Browser Note: For the best experience, scroll to the bottom of the Unity window and click the fullscreen icon. Press ESC to exit.
IEnumerator RollRoutine()
{
isRolling = true;
animator.SetTrigger("Roll");
// Switch to roll collider
standingCollider.enabled = false;
rollCollider.enabled = true;
float t = 0f;
float dir = spriteRenderer.flipX ? -1f : 1f;
while (t < rollDuration)
{
// Apply roll velocity
velocity.x = dir * rollSpeed;
targetVelocity.x = velocity.x;
// Bounce off walls
if (HitWall(dir))
dir *= -1f;
t += Time.deltaTime;
if (velocity.x > 0.1f) spriteRenderer.flipX = false;
if (velocity.x < -0.1f) spriteRenderer.flipX = true;
yield return null;
}
rollCollider.enabled = false;
standingCollider.enabled = true;
isRolling = false;
// Prevent clipping into ceilings
if (!CanStandUp())
{
StartCoroutine(RollRoutine());
}
}