Search Unity

2D use MousePosition for Weapon Rotation with Camera Angle

Discussion in 'Editor & General Support' started by givizator, Sep 29, 2020.

  1. givizator

    givizator

    Joined:
    Oct 23, 2018
    Posts:
    30
    Hey,
    Here is the setup :



    The yellow line is the mouse position on the screen using Camera.main.ScreenToWorldPoint.
    The red line is the mouse position on the ground using a raycast to the ground collider.
    The camera is setup with a 30 degrees X rotation angle.

    My goal is to convert the raycast hitpoint (red line) with the ground on the screen position to be able to rotate the character weapon properly into the mouse direction, considering the camera 30 angle.

    How can I approach that conversion ? WorldToScreenPoint is not giving good results.

    Thanks !