Search Unity

Player 1 will not turn, if already moving forward

Discussion in 'Input System' started by Adjaar7, Jan 1, 2021.

  1. Adjaar7

    Adjaar7

    Joined:
    Jan 6, 2020
    Posts:
    22
    Using the new Input system, I finally am figuring things out, but I have a major problem. InputAction.CallbackContext seems to shut off the moment it detects anything, and won't take additional input if it already has one.

    Basically in my game you move a ship forward with 'W', and you can use 'A' and 'D' to turn. With the new system I can only choose to either a) Move forward. b) Turn the ship. c) move and turn at the same time. Option C is what I need, and I can only do it if I held w&a or w&d from the start. I cannot hold w and then later on press a or d.

    This grabs input no problem
    Code (CSharp):
    1. public void Move(InputAction.CallbackContext ctx)
    2.     {
    3.         moveInput = ctx.ReadValue<Vector2>();
    4.         Debug.Log(moveInput);
    5. }
    The ship does move. This gets called in a fixed update
    Code (CSharp):
    1.     void ApplyMovement()
    2.     {
    3.         steeringAmount = moveInput.x;
    4.         speed = moveInput.y * accelerationPower;
    5.         direction = Mathf.Sign(Vector2.Dot(rb.velocity, rb.GetRelativeVector(Vector2.up)));
    6.         rb.rotation += steeringAmount * steeringPower * rb.velocity.magnitude * direction;
    7.  
    8.  
    9.         rb.AddRelativeForce(-Vector2.up * speed);
    10.  
    11.         rb.AddRelativeForce(-Vector2.right * steeringAmount);
    12.     }
    Is there a fix for this?