I am getting a mouse position using the New Input System.
I want to rotate the character to the mouse position. However, the mouse position detects out of the game view, so normal rotation is impossible.
Input Debugger’s ‘Lock Input To Game View’ option is also ineffective.
I spent a lot of time because of the New Input System. I want to finish this problem. Is there anyone who can help you?
#region aiming position
playerControls.PlayerMovement.Aiming.performed +=
context =>
{
aimingInputs = context.ReadValue<Vector2>();
Vector3 worldPos = Vector3.zero;
worldPos.x = aimingInputs.x;
worldPos.z = aimingInputs.y;
Vector3 tempPos = Camera.main.ScreenToViewportPoint(worldPos);
Vector3 currentPos = transform.position;
Vector3 dirToTarget = worldPos - currentPos;
Quaternion targetRotation = Quaternion.LookRotation(dirToTarget);
Quaternion playerRotation = Quaternion.Slerp(transform.rotation, targetRotation, 20f * Time.deltaTime);
transform.rotation = playerRotation;
};
#endregion