Accurate LookAt with offset
Hi ! I have a character looking at the mouse position (converted to 3d space with raycasting).
In this screen, the green line represent the raycast from character pivot point to mouse cursor. The red line represent the gun aiming raycast. I want the red line is done at mouse cursor, by rotating character.
This is the code of the LookAtMouse script (C#).
public class LookAtMouse : MonoBehaviour
{
void FixedUpdate ()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Vector3 playerToMouse = (hit.point - transform.position);
transform.rotation = Quaternion.LookRotation(playerToMouse);
}
}
}
I don't know what to do... I tryed with offset, but without success.
Thank you in advance for your help. :)
sans-titre.png
(36.0 kB)
Comment