# Axis Gravity / Smoothing?

Discussion in 'Input System' started by Kreesty, Jul 31, 2020.

1. ### Kreesty

Joined:
Feb 21, 2016
Posts:
11
Is there any way to add gravity to a Vector2 value like you could in the old input system?

Joined:
Sep 6, 2013
Posts:
97
3. ### Kreesty

Joined:
Feb 21, 2016
Posts:
11
That seems to work for a regular float, but doesn't work for a Vector2 which goes between -1 and 1.

4. ### uani

Joined:
Sep 6, 2013
Posts:
97
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.

5. ### Kreesty

Joined:
Feb 21, 2016
Posts:
11
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.

Code (CSharp):
1. private Vector2 moveVector;
2. private float gravityX;
3. private float gravityY;
4.
5. private float inputAcceleration = 6f;
6. private float inputDeceleration = 5f;
7.
8. public void Move(InputAction.CallbackContext ctx)
9. {
11. }
12.
13. public virtual void MoveInput()
14. {
15.     if (moveVector.x == 0)
16.     {
17.         gravityX = Mathf.MoveTowards(gravityX, 0f, Time.deltaTime * inputDeceleration);
18.     }
19.     else
20.         gravityX = Mathf.MoveTowards(gravityX, moveVector.x, Time.deltaTime * inputAcceleration);
21.
22.     if (moveVector.y == 0)
23.         gravityY = Mathf.MoveTowards(gravityY, 0f, Time.deltaTime * inputDeceleration);
24.     else
25.         gravityY = Mathf.MoveTowards(gravityY, moveVector.y, Time.deltaTime * inputAcceleration);
26.
27.     gravityX = Mathf.Clamp(gravityX, -1, 1);
28.     gravityY = Mathf.Clamp(gravityY, -1, 1);
29. }

Last edited: Aug 2, 2020
unityunity