Skip to content

move input stop working and gets working again if i press another input #677

@anynoise00

Description

@anynoise00

I'm new to programming and i'm using this new input system, i'm creating a simple player movimentation system for a platform game. I did the code below

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

public class Player : MonoBehaviour, InputMaster.IPlayerActions
{

    [SerializeField] float moveSpeed = 7f;
    [SerializeField] float jumpValue = 6f;

    Rigidbody2D rb;
    InputMaster controls;

    Vector2 moveInput;

    private void Awake()
    {
        controls = new InputMaster();
        controls.Player.SetCallbacks(this);
    }

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

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

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    private void FixedUpdate()
    {
        Move();
    }

    private void Move()
    {
        rb.velocity = new Vector2(moveInput.x * moveSpeed / 0.02f * Time.deltaTime, rb.velocity.y); 
    }

    private void Jump()
    {
        rb.velocity = transform.up * jumpValue;
    }

    //inputs
    public void OnMove(InputAction.CallbackContext context)
    {
        moveInput = new Vector2(context.ReadValue<float>(), 0f);
    }

    public void OnJump(InputAction.CallbackContext context)
    {
        Jump();
    }

    public void OnCrouch(InputAction.CallbackContext context)
    {
        Debug.Log("We want to crouch!");
    }

    public void OnInteract(InputAction.CallbackContext context)
    {
        Debug.Log("We want to interact!");
    }

    public void OnAttack(InputAction.CallbackContext context)
    {
        Debug.Log("We want to attack!");
    }

    public void OnLook(InputAction.CallbackContext context)
    {
        Debug.Log("looking");
    }
}

but when testing it, i noticed that if i kept pressing buttons to move left and right, it sometimes stop, even if i'm with the A or D key pressed(let's say that the input system is paused). I can get my player moving again if i release the key and then press it again, or striking another input key, it's like it unpause the input system.

PS: i'm using 1D axis and keyboard to move

And sorry for my bad english, i don't know if someone will understand what i wrote

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions