Search Unity

Rotate the object towards mouse direction when camera is static

Discussion in 'Scripting' started by nothingn0, Feb 14, 2019.

  1. nothingn0

    nothingn0

    Joined:
    Feb 12, 2019
    Posts:
    3
    1. Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    2. transform.rotation = Quaternion.LookRotation(Vector3.forward, mousePos - transform.position);

      Problem solved guys.
     
    Last edited: Feb 15, 2019
  2. Helladah

    Helladah

    Joined:
    May 5, 2018
    Posts:
    254
    well, thanks for share the answer XDDD, so if anyone have the same question jst have to ask again.