Hello,
I have a character controller that uses the input axis to determine the direction of the rigidbody.
With a controller it works fine. But with keys the character moves extra fast when the horizontal and vertical axis are pressed. This isn’t surprising, because with a controller the X and Y axis can never be more than 1 when you add them. But with keys they can both be set to 1, which means that the character will get force on the X and Z axis at full power. So it moves faster.
So what’s a good way of capping them without a delay? I have this now, but it does have a slight delay.
// In the update
void Update()
{
//so this is supposed to cap the axis.
//hor and ver are the axis from the input. ( I.E. Input.GetAxis(Horizontal))
if((hor == 1f || hor == -1f) && (ver == 1f || ver == -1f))
{
hor = hor * 0.5f;
ver = ver * 0.5f;
}
}
//Late update for physics.
private void LateUpdate()
{
// Adds the force to the character.
rigid.AddForce(new Vector3(hor, 0, -ver) * status.speed);
}