I am developing a 3rd Person Controller.
The hero’s chest should be rotated towards a point on the screen.
To determine the point, I use the following code:
var mousePos = Input.mousePosition; mousePos.z = 10; // Make sure to add some "depth" to the screen point var aim = Camera.main.ScreenToWorldPoint(mousePos);
Then I rotate the chest like this:
Vector3 v = new Vector3(0, aim.x, 0); Chest.Rotate(v);
It does work, but it rotates only minimally, and the the direction is inverted: If the mouse is on the right of the screen, the chest rotates to the left and vice versa.
Also, I’m not sure how to include the model’s overall rotation (but I don’t know yet if that is necessary).
Does anybody have any idea what I’m doing wrong?
When I add more depth to it, it rotates much more:
var mousePos = Input.mousePosition; mousePos.z = 100; // Make sure to add some "depth" to the screen point var aim = Camera.main.ScreenToWorldPoint(mousePos);
But I have no idea how much depth is actually needed.
If I add 1000, it rotates like crazy.
So I would like to know how to calculate the amount of depth that should actually be added to the screen point.