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;
}
}