Axis Gravity / Smoothing?

Is there any way to add gravity to a Vector2 value like you could in the old input system?
Please, I really need this.

is a substitute.

If you need gravity being different from sensitivity the code needs to be modified to be a little bit more intricate.

2 Likes

That seems to work for a regular float, but doesn’t work for a Vector2 which goes between -1 and 1.

can Input Manager do gravity for analogue input which would yield a Vector2?

If the input is analogue, I would expect the data to represent the input exactly.

If you have a combined digital input I am only aware of new Input System having combinations representing several individual digital bindings, thus you could have a vector2 with each of its components being either (-)1 or 0.

If the new input system can combine 2 digital bindings to a continuous value from -1 to 1 it might do its own gravity and sensitivity I am not aware of and neither know how to modify; but that would be a single value not a Vector2.

Alright so, I know this is not ideal since it’s doing the calculations every frame, but it works for now. Would love an official solution to be added in the future.

private Vector2 moveVector;
private float gravityX;
private float gravityY;

private float inputAcceleration = 6f;
private float inputDeceleration = 5f;

public void Move(InputAction.CallbackContext ctx)
{
   moveVector = ctx.ReadValue<Vector2>();
}

public virtual void MoveInput()
{
    if (moveVector.x == 0)
    {
        gravityX = Mathf.MoveTowards(gravityX, 0f, Time.deltaTime * inputDeceleration);
    }
    else
        gravityX = Mathf.MoveTowards(gravityX, moveVector.x, Time.deltaTime * inputAcceleration);

    if (moveVector.y == 0)
        gravityY = Mathf.MoveTowards(gravityY, 0f, Time.deltaTime * inputDeceleration);
    else
        gravityY = Mathf.MoveTowards(gravityY, moveVector.y, Time.deltaTime * inputAcceleration);

    gravityX = Mathf.Clamp(gravityX, -1, 1);
    gravityY = Mathf.Clamp(gravityY, -1, 1);
}
9 Likes