I’m setting up my game to use a controller. I just added the ability to use the D-pad to control the player. In my game the player only moves in four directions anyway. I’m using the new input system.
But sometimes I will change direction and the player won’t change; I move my thumb to press a new direction, but the player responds like I’m still holding down the old direction.
I’m not sure what the problem is; maybe I’m moving too fast, maybe I’m sliding my thumb, whatever the cause I can’t reproduce the effect 100% of the time, but it does seem to happen when I make quicker motions.
Has anyone else had a similar problem? This is a very critical issue to my gameplay; I can’t release a game where the player sometimes doesn’t respond to player input.
I don’t think this is a problem with my code, because it only happens with the D-pad. If I use the keyboard arrows, I can make all the quick motions and sliding I want without any problems.
But just to be sur, here’s the code for my input:
void OnMove(InputValue value)
{
//Vector3 Movement = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")) * moveSpeed;
Vector2 TwoMovement = value.Get<Vector2>();
if (TwoMovement.magnitude < 0.1f) // @@@ Aaaack!
{
Movement = Vector3.zero;
Anim.SetAnimation(Animation.Idle);
return;
}
if (bRunMode)
{
Anim.SetAnimation(Animation.Run);
}
else
{
Anim.SetAnimation(Animation.Walk);
}
if (Mathf.Abs(TwoMovement.x) > Mathf.Abs(TwoMovement.y))
{
//We are moving horizontal
if (TwoMovement.x > 0)
{
Movement = Vector3.right * TwoMovement.magnitude;
}
else
{
Movement = Vector3.left * TwoMovement.magnitude;
}
}
else
{
//We are moving vertical
if (TwoMovement.y > 0)
{
Movement = Vector3.forward * TwoMovement.magnitude;
}
else
{
Movement = Vector3.back * TwoMovement.magnitude;
}
}
if (bRunMode)
{
Movement *= RunSpeed;
}
else
{
Movement *= moveSpeed;
}
SetFacingAngle( Direction.VectorToDirection(Movement));
Anim.UpdateFacingDirection(facingDirection);
}
And then in FixedUpdate the Movement variable is fed into the character controller.
As you can see, I first check for a zero direction, and then find which of the four directions the player’s input is closest to, and then apply the input’s magnitude to that direction.
The character’s game object maintains the same rotation because it has a sprite that must face the camera; the “set Facing Angle” and “Anim” functions handle that.
Is there some property I am not setting in the Input Actions? Why is the D-pad sometimes not registering a change in its value?