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\$
  • \$\begingroup\$ Is this a top down game, or a platformer or something else? \$\endgroup\$ – Millard Aug 31 '19 at 13:24
  • \$\begingroup\$ You can switch between top down and ego \$\endgroup\$ – Mirco Sep 16 '19 at 17:46
-3
\$\begingroup\$

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

| improve this answer | |
\$\endgroup\$
  • 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 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.