Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

I tried putting the characterMovement and ground script into a new unity project but can't move when I press keys. How do you get these scripts to work?

(1 edit)

Personally, i do some change in the code but it’s working :
Original

    public void OnMovement(InputAction.CallbackContext context)
    {
        //This is called when you input a direction on a valid input type, such as arrow keys or analogue stick
        //The value will read -1 when pressing left, 0 when idle, and 1 when pressing right.

        if (moveLimit.characterCanMove)
        {
            directionX = context.ReadValue<float>();
        }
    }

My modified version

    public void OnMovement()
    {
        //This is called when you input a direction on a valid input type, such as arrow keys or analogue stick
        //The value will read -1 when pressing left, 0 when idle, and 1 when pressing right.
        directionX = UnityEngine.Input.GetAxis("Horizontal");
        directionX = directionX != 0 ? directionX / Mathf.Abs(directionX) : 0; //Set the var at 1 if > 0, -1 if < 0;
    }

private void Update()
{
    OnMovement();
    ...

Maybe there’s a better/simpler way, but this work so you can try it

Thanks so much!