Beginner at new input system, character doesn't move?

Hello. I am working on a game with more physics-based fighting, and wanted to try the new Input system- which is really not new anymore, but…

I have the input system for the player to have two different positive and negative bindings- one for the X Axis, and one for the Y axis. I would like to, for a test, have the player move left and right, swim down, and swim up or jump in the 2D water. At this stage, it doesn’t even move. FYI, speed = 10, and the PlayerController is actually the Input system. I have this in the Update() function. Movement is a Vector2.zero which is supposed to be the one that contains the values for the PlayerController to read.

PlayerController.ReadValue();
RB.velocity = new Vector2(movement.x * speed, movement.y * speed);

Again, this character does not budge. The rigidBody2D has a mass of 1, so it isn’t about that- I just switched it from its original number, which was 2. I checked and the everything is bound to the arrow keys. What am I missing here?

Thank you.

8430068--1116167--Screenshot (583).png

Show the full code using code tags

The speed and jumpHeight are from using the old input system, though I can still use the speed.

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

public class PlayerScript : MonoBehaviour
{

    public float speed = 10;
    public float jumpHeight = 2;

    float modifier = 1f;
    float vertModifier;
    Rigidbody2D RB;
    bool inWater;
    bool onGround;

    bool isColliding;

    public InputAction PlayerController;

    Vector2 movement = Vector2.zero;

    private void OnEnable()
    {
        PlayerController.Enable();
    }

    private void OnDisable()
    {
        PlayerController.Disable();
    }

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

    private void Update()
    {
        onGround = GroundCheck.onGround;
        inWater = GroundCheck.inWater;
        isColliding = HeadCheck.isColliding;

        PlayerController.ReadValue<Vector2>();
        RB.velocity = new Vector2(movement.x * speed, movement.y * speed * 2);
    }

    // Update is called once per frame
    void FixedUpdate()
    {
    }

You read the value but don’t use it or cache it, so obviously it won’t work.
Also put the values in debug.logs to see what they are so you can understand your code better

I’m lost. I never heard of cache in Unity before. Plus I’ve only ever coded objects to move before- not just in Unity, so this is very new.

I thought you meant something like this, but it still won’t budge.

    private void Update()
    {
        onGround = GroundCheck.onGround;
        inWater = GroundCheck.inWater;
        isColliding = HeadCheck.isColliding;

        movement = PlayerController.ReadValue<Vector2>();
        Debug.Log(movement.x);
        RB.velocity = new Vector2(movement.x * speed, movement.y * speed * 2);
    }

I snagged it from another code of the forum.

  • using UnityEngine;
  • using UnityEngine.InputSystem;
    • public class PlayerMovement : MonoBehaviour
  • {
  • private Vector2 m_PlayerMovement;
  • private InputAction m_MoveAction;
  • private InputAction m_AttackAction;
    • void Start()
  • {
  • m_MoveAction = new InputAction(“Move”);
  • m_MoveAction.AddBinding(“/leftStick”);
  • m_MoveAction.Enable();
    • m_AttackAction = new InputAction(“Attack”, binding: “/buttonSouth”);
  • m_AttackAction.Enable();
  • }
    • void Update()
  • {
  • m_PlayerMovement = m_MoveAction.ReadValue();
  • if(m_PlayerMovement != Vector2.zero)
  • Debug.Log("Vector = " + m_PlayerMovement);
    • var attacking = m_AttackAction.ReadValue();
  • if(Mathf.Approximately(attacking, 1f))
  • Debug.Log(“Attacking”);
  • }
  • }

With cache I ment having a local variable which you store the vector into.

What does the debug log give?
Did you google ‘2d character controller new input system’ already? Found many guides there

I don’t have a character controller, it’s a rigidbody2d with an input system named PlayerController. As stated before, this has a LOT of physics. A character controller, I fear, won’t be enough.

I get a bunch of zeros on the Debug.log.

That meant the action isn’t bound.

And a RigidBody2D that controlls a character can also be concidered a character controller (;
Just look up some guides since these are the basics

Sorry, I thought you meant the actual component character controller.

And believe me when I say I already looked for guides- on the Unity website, on Youtube…

On the flip side, are they planning on removing the old system any time soon? If not, I could just use that.

Not that I know, feel free to use it

@ you are using the new system incorrectly. Please have a look at this Quick start guide | Input System | 1.4.4.

I read the docs, and I don’t have a joystick or gamepad. I want to move with arrow keys, WASD, and space for a 2D platformer. I don’t know how to tell the device to use the actions for the basic movements.

Which Unity version do you use? If I update my project to the latest Unity and Input version I no longer get input for Vector2s, but it do work in previous versions. Could be related to this: What are the causes of these errors?

I have Unity 2021.3.6f1…

Good to know.

Movement isn’t thought of as a button, but a value. Specifically a vector 2 value. You can then use a composite binding for up/down/left/right to define WASD. You can also add gamepad and joystick to that action. This can all be done in the input action asset.

I suggest you follow a more recent tutorial on youtube. The Input system isn’t that hard to use, you just have to learn how it works a bit.