Search Unity

Diagonal Movement still faster with both Clamp Magnitude and/or Normalize

Discussion in '2D' started by Blitz54, Mar 6, 2021.

  1. Blitz54

    Blitz54

    Joined:
    Dec 20, 2020
    Posts:
    20
    So, I have a top down 2D game. I'm using Bolt, and the Rewired asset. I'm using keyboard, having A+D act as Horizontal Axis, and W+S act as the Vertical. I tried both update and Fixed Update.

    The way I have my Flow graph set up currently, is that when either axis is active, the Rewired Event Node will turn on, and will add the values to a Vector2. I then take that Vector2, and Normalize it. Then, I clamp the normalized result. I've tried just Normalizing, and just Clamping, but both give the same issue. If I'm holding D and going right at a value of 1, I can spam the W+S and cross distances quicker. If I just hold right, it takes me 5 seconds to cross a set distance. If I spam the other axis, it takes 3 seconds.

    When I'm going exactly diagonal for a second or two, the Vector does show 0.7 x 0.7. But spamming the second axis will keep the first axis value at 1, but increase the second one up to 0.3 before it changes.

    Am I dumb? I'm really not sure how to prevent exploiting spamming keys in this situation. Thanks.
     
  2. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    i suggest that you use actual c# code for this part of your game if your 3rd party plugins are not working correctly

    when you code movement you are supposed to get a vector2 that gets the x from the horizontal axis and y from vertical axis, you then normalize that vector and multiply it by your speed, no need for clamping
     
    OddSocksDev likes this.
  3. Blitz54

    Blitz54

    Joined:
    Dec 20, 2020
    Posts:
    20
    From what I had read people used either or. By using Normalize you can only move at full speed when moving, so analog sticks wouldn't give you the option to slowly walk. Clamping gives the same result, but still allows you to walk slowly, and adds a small acceleration if using keyboard. In my case I don't necessarily need the ability to walk slower, but it would have been a nice addition.

    Bolt is "made" by Unity, and Rewired really shouldn't change anything. But I'll try regular code next.
     
    Last edited: Mar 6, 2021