Hi all,
Currently, I am trying to use both GetAxisRaw (for ground movement) and GetAxis (for air movement) in my game. The reason I have configured it like this is because when I jump in my game with horizontal movement for example, I want the momentum to keep the player going.
If I use GetAxisRaw for this, the value changes from 1 to 0 instantly and the player stops moving as soon as I let go of the button.
The code is as follows:
if (controller.isGrounded)
{
horizontal = Input.GetAxisRaw("Horizontal");
vertical = Input.GetAxisRaw("Vertical");
}
else if (!controller.isGrounded)
{
horizontal += Input.GetAxis("Horizontal");
vertical += Input.GetAxis("Vertical");
}
This works fine and gives me the desired affect. The problem is when my player is grounded and starts running, if I’m holding down two keys (W + A for example), it appears as though the GetAxis value is increasing because if I let go of one of the keys (A in this case) and then jump, my player jump diagonally instead of forward.
I can see in the inspector that both horizontal and vertical values are at 1 or 0 in the inspector, but as soon as I jump, the value changes to a float range equal to how long I was holding the button, leading to diagonal jumping.
Does anyone know why the axis value is increasing even when I’m grounded? Or how I can prevent this problem? I hope I explained it well, let me know if I can provide any further information.
Regards
Jason