I assume you already have an Input Action asset with an action "Move" of control type "Vector2" that has bindings for both the joystick and the WASD keys and that you added a PlayerInput component to your scene.
If your PlayerInput component is configured to "Send Messages", then your method needs to be on the same gameobject as the PlayerInput component and have a method which looks like this:
public void OnMove(InputValue value)
{
Vector2 input = value.Get<Vector2>();
}
If your PlayerInput component is configured to use UnityEvents, then the method you bind to the Move action via inspector needs to look like this:
public void OnMove(InputAction.CallbackContext context)
{
Vector2 input = context.Get<Vector2>();
}
The vector you receive has x and y components between -1 and +1. For keyboard keys and other digital input buttons, those will always be 1.0f
, 0f
or -1.0f
. But joysticks are analog input devices which will deliver floating-point values anywhere in this range. So if you want to support both digital and analog input devices, you need to check for ranges, not for equality.
Now all you need to do is map the possible values of the input vector to specific positions and then set the transform.position
to that position. I could go into further detail, but your question is too vague to tell what your actual requirements are in this regard.