How do I Make a Top-Down Roll in Unity, Using the New Input Sytem?

I’ve been trying to make a roll for my top-down game, but I can’t find a tutorial that is easy to change from old input to new input, and I can’t find a new input version. If someone could help me figure this out, I would greatly appreciate it! Here’s my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class TopDownController2D : MonoBehaviour
{

    private Rigidbody2D rb;

    public float speed;

    private Vector2 movement;
    private bool isFacingRight;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    // Stores the X and Y values for the Movement
    public void Move(InputAction.CallbackContext context)
    {
        movement = context.ReadValue<Vector2>();
    }

    // Makes the player dash
    public void Dash(InputAction.CallbackContext context)
    {

    }

    // Update is called once per frame
    void Update()
    {
        rb.velocity = new Vector2(movement.x, movement.y) * speed;

        if (!isFacingRight && movement.x < 0f)
        {
            Flip();
        }
        else if (isFacingRight && movement.x > 0f)
        {
            Flip();
        }
    }

    // Flips the Character
    private void Flip()
    {
        isFacingRight = !isFacingRight;
        Vector3 localScale = transform.localScale;
        localScale.x *= -1f;
        transform.localScale = localScale;
    }
}

One thing at a time… Steps to success:

  • find a Roll tutorial using the OLD input system

  • stand that up and iterate with it in a brand-new empty project until the code works precisely as you want (just use placeholder graphics / sprites to test)

  • once the roll works perfectly with the old input system, refactor the code into linear stages of operation:

—> read the old input system
—> when roll is commanded by old input, set a private bool doRoll; to true
—> when the doRoll is true, actually perform the roll code
—> when you actually do the roll, clear the doRoll boolean to false

Once you have ALL of that working, stop.

Now graft that function back into your current project, reattach everything.

Finally, REMOVE the code that reads the old input system and replace it with new input system reading code.

The only line that changes will be the bold line above, NOTHING else changes.

If you are unsure how to read from the new input system, go through the tutorials on it again.