Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question input.mousePosition is broken

Discussion in 'Input System' started by SpoopyIsSad, May 8, 2022.

  1. SpoopyIsSad


    Dec 29, 2020
    I have a gun attached to a player but for whatever reason the gun points towards the player and not the mouse.
    I don't know why. It just started today but was working fine before?

    this is the script on the weapon which SHOULD be pointing towards the mouse

    void faceMouse()
    Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
    float rotation_z = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
    transform.rotation = Quaternion.Euler(0f, 0f, rotation_z + offset);

    edit :

    wow I wrote this really poorly! But after like a week of trial and error I found out that my camera was on perspective and not orthographic... fantastic!

    this was basically the forum with my same problem
    Last edited: May 14, 2022
    Itsu_Bitsu likes this.