Controlling Animation via Mouse

Hi,

I want to control my animation via mouse movement/drag. So if my mouse was towards the bottom of the screen it would be at 0, if my mouse was in the middle of the screen it would be at 0.5, and if my mouse was on the top of the screen it would be at 1.

Here is some code so far:

vertAxisMouse = Input.GetAxis("Mouse Y");
	vertAxisMouse *= Time.deltaTime;
	vertAxisNormalizedMouse = Mathf.Clamp(vertAxisMouse, 0.000, 1.000);
	playerOneAnim["toss"].normalizedTime = vertAxisNormalizedMouse;
	Debug.Log("Axis: " + vertAxisMouse + "Normalized: " + vertAxisNormalizedMouse);
	playerOneAnim["toss"].time = vertAxisMouse;

Nothing happens though. Comments Welcome :slight_smile:

One thing I noticed at first glance: don’t use Time.deltaTime when dealing with mouse axes. That’s already frame-rate independent to begin with, so multiplying by deltaTime makes it frame-rate dependent (somewhat ironically).

Anyway, in this case, you don’t want to use the Y mouse axis at all. From what you described, you’d want to use Input.mousePosition.y, and divide by Screen.height.

–Eric

Thanks, works perfectly now.