Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question I'm stuck in the ground

Discussion in 'Input System' started by Jeison_, Dec 1, 2020.

  1. Jeison_

    Jeison_

    Joined:
    Oct 12, 2020
    Posts:
    7
    I can't jump if I move and if I jump I can't move...
    upload_2020-12-1_8-46-51.png
    Jump is a Button.
    now I notice that if I comment out my run method I'm able to jump, but yeah I can't move and if I uncomment run then what happens? yup I can move but then I can't jump...
    here's my code:

    Code (CSharp):
    1.  
    2.     private PlayerControls inputActions;
    3.     Rigidbody2D rb;
    4. private void Awake()
    5.     {
    6.         inputActions = new PlayerControls();
    7.         rb = GetComponent<Rigidbody2D>();
    8.      }
    9.  
    10.  private void Start()
    11.     {
    12.         inputActions.Player.Jump.started += _ => Jump();
    13.     }
    14. private void FixedUpdate()
    15.     {
    16.         if (!isAlive) { return; }
    17.         Run();
    18.     }
    19.  
    20.     private void Run()
    21.     {
    22.         Vector2 moveInput = inputActions.Player.Movement.ReadValue<Vector2>();
    23.         rb.velocity = moveInput * speed;
    24.     }
    25.  
    26.     private void Jump()
    27.     {
    28.         rb.velocity += Vector2.up * 10;
    29.         Debug.Log("Im jumpling");
    30.     }
    I want to jump with physics I prefer that in this case instead of moving with transform.
     

    Attached Files: