LookAtOffset follow the mouse position

Jorgefo

New member
Hi

I try to make the character look at mouse position but the character look to other side.


This is my code
C#:
void Update()
    {
        screenPosition = Input.mousePosition;
        Ray ray = mainCamera.ScreenPointToRay(screenPosition);
        if(Physics.Raycast(ray, out RaycastHit raycastHit, 100, layersToHit)){
            charIK.LookAtOffset = raycastHit.point;
            transform.position = raycastHit.point;
        }
    }


But the character see to another direction, in the screenshot the character see to the line green but the right is to see the blue point
 

Attachments

  • Screen Shot 2022-08-12 at 13.36.32.png
    Screen Shot 2022-08-12 at 13.36.32.png
    567.1 KB · Views: 3
The LookAtOffset is a direction, not a position. So in order for that to work you'll want to set a directional value.
 
Thanks. I understand my faul


Code:
    void Update()
    {
        screenPosition = Input.mousePosition;
        Ray ray = mainCamera.ScreenPointToRay(screenPosition);
        if(Physics.Raycast(ray, out RaycastHit raycastHit, 100, layersToHit)){
            transform.position = raycastHit.point;
            charIK.LookAtOffset = raycastHit.point - Character.transform.position;

}}

I see this video

 
Top