Search Unity

Question 2D aim with mouse by changing animation parameter?

Discussion in 'Input System' started by CystemCV, Sep 18, 2022.

  1. CystemCV

    CystemCV

    Joined:
    May 7, 2022
    Posts:
    29
    Need help on this thing...so an asset I bought has an animation parameter called Aim. If i set that parameter to 1 the character aims up, on 0 it aims in front and on -1 it aims down.

    upload_2022-9-18_15-39-11.png

    So far so good. The concept was easy enough to do and work on the controller. I did a Vector 2 for the right stick and I just assign the y value . It works very good for the controller.
    upload_2022-9-18_15-41-19.png

    My problem now is with the mouse...how I can do the same with the mouse? The parameter reads from 1 to -1...so i have no idea what to do now.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Two possible ways:

    - absolute controls: map the mouse X (or Y?) axis to this aim value. In this case, divide the desired mouse axis by either Screen.width or Screen.height . To ensure that a floating point divide is done, you may want to cast at least one argument to the divide to a float.

    - relative controls: have your own notion of "aim angle" from -1 to 1, and use relative movement of the mouse to change that number each frame, again likely dividing it by some large number such as the screen dimensions above.

    You may wish to do a little bit of testing, reading the desired mouse position, dividing it, printing the result to Debug.Log() so you get a feel for what is going on.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    So you know, this isn't a post about 2D but there's a whole forum for the Input System so I'll move your post there.