# Make input relative to rotation

asked Aug 27, 2016 in Math
So, i have a 2D blend tree where is my fully animated character (walking forward backward, running, etc...). I am controlling the blend tree with Horizontal and Vertical Input axis. The problem is, the animations play correctly only when the character is facing forward (y rot = 0). When he faces left (y rot = 270) and i press D, he starts walking in the up direction. My problem is that i dont know how to convert the input so that he would walk in the right direction(y rot = 90). I tried many things and none have worked. Thanks.

+1 vote
answered Aug 27, 2016 by Senior (4,800 points)
selected Aug 27, 2016

You have to handle the input like a vector in 2D space. Then transform it to the characters local space. Fortunately this can be done very easily in 2D space. The animation should then be blended using the transformed input vector.

```    float x = Input.GetAxis("Horizontal");
float y = Input.GetAxis("Vertical");

Vector3 worldInput = new Vector3(x, y, 0);
Vector3 localInput = transform.InverseTransformDirection(worldInput);```

commented Aug 27, 2016 by Student (370 points)
Tried it but it doesnt fully work. For example when im looking right (y = 90) and press A or D it doesnt move horizontally, it doesnt move at all. Any ideas?
commented Aug 27, 2016 by Senior (1,150 points)
I think the coordinates have to be switched. What is your characters forward axis? Could you post a link to a video or a screenshot?
commented Aug 27, 2016 by Student (370 points)
Yeah you were right! Damn bugstacker, youre a lifesaver! Thank you! :)