I have created a Third Person Controller. The camera is behind the player:
I would like to make it so that the player aims at the mouse pointer position.
To do that, I use the following code to rotate the chest towards the position:
var mousePos = Input.mousePosition;
mousePos.z = 10; // Make sure to add some "depth" to the screen point
var aim = Camera.main.ScreenToWorldPoint(mousePos);
Chest.LookAt(aim);
The hands do not perfectly straightly point forwards, so I need to add an "offset" to the LookAt.
I tried this approach:
var mousePos = Input.mousePosition;
mousePos.z = 10; // Make sure to add some "depth" to the screen point
var aim = Camera.main.ScreenToWorldPoint(mousePos);
aim += new Vector3(ChestAimCenterOffsetForLookatBecauseChestIsNotStraightForward, 0, 0);
Chest.LookAt(aim);
Of course I do all rotation patching in LateUpdate(). In Update(), it would simply be erased by the animation itself.
It does work, but when the model is rotated around the Y axis, something goes wrong: The offset is "wrong", it doesn't have the same effect.
This surprises me because all I do is rotate the entire model.
So I think this line is not correct:
aim += new Vector3(ChestAimCenterOffsetForLookatBecauseChestIsNotStraightForward, 0, 0);
Is this not the way to offset the LookAt results?
Chest.LookAt(aim)
affecting the model at all? \$\endgroup\$