2D aim with mouse by changing animation parameter?

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.

8447762--1120385--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.

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.

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.

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.