Complicated and overloaded

as the title says, a simple prototyping isnt possible anymore with this monster system

what is the quickest way to just have a horizontal and vertical axis value between +1 and -1
pressing WASD , how to read them and from where, i ended up writing a method like
public void OnMove(InputAction.CallbackContext context)
{

}

now how to do something useful with “context”
the documentation is bad and runs away from its own problems by
showing an “event” Move and then there is a code but not about move its just “fire”

here Unity Blog
read and cry…

is there any official video tutorial or similiar that shows you how to get seriously productive with this madness ?

Ok, so I have a similar issue as I can’t even figure out how to make a character jump, and no idea how animations are to come into play and work with any of this, but I wanted to try this out seeing as it is here to stay. I am a quick learner and I know programming and have been programming for a while. That being said I am using a character controller. I have the movement working so far but no idea how to implement a jump function yet. Hope this helps somehow, I saw this post had a lot of view but no replies, so hopefully someone has more info than me.

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

public class PlayerMovement : MonoBehaviour
{
    //variables
    private NewControls controls;
    [SerializeField]
    private float movementSpeed = 1.0f;
    [SerializeField]
    private float jumpSpeed = 8f;
    [SerializeField]
    private float gravity = 20f;
    private Vector2 move;
    private Vector3 movement = Vector3.zero;
    //private Transform moveY;//put back later
    //private InputAction jumpAction;//trying to find a way to jump
    //private GameObject cam; //might not need
    private CharacterController characterController;


    // Start is called before the first frame update
    void Awake()
    {
        //find that  boi
        characterController = GetComponent<CharacterController>();

        controls = new NewControls();

        controls.Player.Jump.started += ContextCallback => Jump();
    }

    // Update is called once per frame
    void Update()
    {
        if(characterController.isGrounded)
        {
            //get the movement from the input manager
            //input here is coming from the keyboard values WASD, Arrow Keys, or PS4 Left Stick
            move = controls.Player.Movement.ReadValue<Vector2>();

            //NOT SURE: Might move the axis based on input direction???
            movement = (move.y * transform.forward) + (move.x * transform.right);
        }

        //apply gravity
        movement.y -= gravity * Time.deltaTime;

        //Apply the inputs into the character controller
        characterController.Move(movement * movementSpeed * Time.deltaTime);

    }

    private void Jump()
    {
        Debug.Log("Jump was called");
        if (characterController.isGrounded)
        {
            Debug.Log("2nd part of Jump was called");
            //send 'em yeetin
            movement.y = jumpSpeed;
           
        }
    }

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

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

So I figured out my jump issue. I just made it so the input action turns a bool true and then it allows the rest to happen under update. inefficient and redundant and the most difficult way to achieve a simple task? Probably. But it works. LOL. Here is my revised code.

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

public class PlayerMovement : MonoBehaviour
{
    //variables
    private NewControls controls;
    [SerializeField]
    private float movementSpeed = 1.0f;
    [SerializeField]
    private float jumpSpeed = 8f;
    [SerializeField]
    private float gravity = 20f;
    private Vector2 move;
    private Vector3 movement = Vector3.zero;
    private bool canYeet;
    //private Transform moveY;//put back later
    //private InputAction jumpAction;//trying to find a way to jump
    //private GameObject cam; //might not need
    private CharacterController characterController;


    // Start is called before the first frame update
    void Awake()
    {
        canYeet = false;
        //find that  boi
        characterController = GetComponent<CharacterController>();

        controls = new NewControls();

        controls.Player.Jump.started += ContextCallback => Jump();
    }

    // Update is called once per frame
    void Update()
    {
        if(characterController.isGrounded)
        {
            //get the movement from the input manager
            //input here is coming from the keyboard values WASD, Arrow Keys, or PS4 Left Stick
            move = controls.Player.Movement.ReadValue<Vector2>();

            //NOT SURE: Might move the axis based on input direction???
            movement = (move.y * transform.forward) + (move.x * transform.right);

            //if statement adding the movement.y
            if(canYeet == true)
            {
                movement.y = jumpSpeed;
                canYeet = false;
            }
        }

        //apply gravity
        movement.y -= gravity * Time.deltaTime;

        //Apply the inputs into the character controller
        characterController.Move(movement * movementSpeed * Time.deltaTime);

    }

    private void Jump()
    {
        Debug.Log("Jump was called");
        if (characterController.isGrounded)
        {
            Debug.Log("2nd part of Jump was called");
            //send 'em yeetin
            //have a true/false bool
            canYeet = true;
           
        }
    }

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

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

If you just want to implement a binding as quickly as possible you can use public InputAction action to generate an action field in the monobehaviour’s inspector.

You can then use action.performed += OnActionPerformedCallback to respond to that action, or whatever other way of reading the action you need (ie ReadValue)

@Bazoo_Studios , for that logic you shouldn’t be using a callback but just calling the “triggered” property of the action which returns true if the action was triggered this frame. eg:

//if statement adding the movement.y
            if(Controls.Player.Jump.triggered == true)
            {
                movement.y = jumpSpeed;
            }
1 Like

Or just don’t bother with bindings and query controls directly:

if (Keyboard.current.wKey.isPressed) {
    // ...
}

if (Keyboard.current[Key.S].wasPressedThisFrame) {
    // ...
}