0
\$\begingroup\$

So, I trying to get used to the new Unity input system. "Back in the days" I just got the Vertical/Horizontal axis, put them into a Vector3, multiplied them by a certain value and then moves the player.

Now, with the new input system, that changed quite a bit. So, what I'm trying to do is, to get the input of a 2D Vector, earlier called DPAD in the new system. My approach was, like

private void Awake() {
    InputAction.performed += ctx => Movement(ctx.ReadValue<Vector2>());
    InputAction.canceled += ctx => Movement(ctx.ReadValue<Vector2>());
}

private void OnMovement(Vector2 _dir) {
    moveDirection = _dir;
}

//This performed in FixedUpdate
private void Move() {
    transform.position += moveDirection * moveSpeed * Time.deltaTime;
}

Buut, you know, kinda worked, but not really. The player did unintended things like keep moving or not reacting at all to my button press. Maybe I set something wrong up. You might help me please, thanks!

\$\endgroup\$
2
  • \$\begingroup\$ Is this a top down game, or a platformer or something else? \$\endgroup\$
    – Millard
    Aug 31, 2019 at 13:24
  • \$\begingroup\$ You can switch between top down and ego \$\endgroup\$
    – Mirco
    Sep 16, 2019 at 17:46

1 Answer 1

-3
\$\begingroup\$

you have to do it like the old input.getaxis. like this: move (Vector2 direction) { t}

\$\endgroup\$
1
  • 2
    \$\begingroup\$ The code shown in the question already seems to do something like this. Can you elaborate on how that code needs to change to apply the fix you're recommending? \$\endgroup\$
    – DMGregory
    Apr 23, 2020 at 13:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .