Search Unity

Moving diagonally with the Vector2

Discussion in 'Input System' started by zh4r0naX, Jun 13, 2019.

  1. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71
    Hello,

    iam trying to get this new input system working. My player char currently just walks directly up / down / left / right. But i never get diagonal movement working. Because once one button is pressed it seems to ignore the other movement buttons. How can i set this up to work ?

    In code iam running:

    m_controls.Player.Movement.performed += ctx => GetMovementVector(ctx.ReadValue<Vector2>());

    while this just stores the vector2 and in fixed update it gets applied to the rigidbody of the object.

    Can you help me?

    Thank you
    Justin
     

    Attached Files:

  2. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71
    Okay so my fault was to take the press and release to stop the character for moving. I simply changed the WASD to continous mode and added some canceled line into the code.


    m_controls.Player.Movement.performed += ctx => movement = ctx.ReadValue<Vector2>();
    m_controls.Player.Movement.canceled += ctx => movement = Vector2.zero;

    This seems to work fine.