Using mouse position for Blend Tree parameter?

Hello,

I am currently trying to make my character aim up, aim neutral and aim down based on mouse position/movement but I do not want to base it on mouse speed/velocity.

It is hard for me to explain the problem or question is so I will just show you a diagram of what I want to do.
See attached image.

Here is a sample of the script

function Aim(){
	var mousePos = Input.mousePosition.y;
		if(Input.GetButton("Zoom")){  //Zoom is right click
			animator.SetFloat("MouseAimY", mousePos); //This will put the number from mouse position (Y axis) coordinate into the parameter.
		
	}
}

Thanks guys!

One idea came to mind. Should I get the camera’s rotation instead?

Awesome community guys.

It tends to die a bit on the weekends - I know I pretty much only check for updates during the week.

Anyway, you probably want to simply divide the mousePosition by Screen.height, and that’ll give you a 0-to-1 value for the y.

Hello,

Thanks for the reply. I do not know what you mean by dividing mousePosition by Screen.height. Like where do I apply it on my script? What to replace or remove?

Thank you.

EDIT: I looked at the Unity docs, it did not gave me an example.

I am new to coding so I learn from using examples and reverse-engineering.

    var mousePos = Input.mousePosition.y / Screen.height;

Then adjust the thresholds in the Mecanim blend tree to match the numbers it now gives you, as desired.

Thank you it worked perfectly!