Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Mouse offset wrong when using sprite cursors

Discussion in '2D' started by bommes21, Jan 23, 2020.

  1. bommes21

    bommes21

    Joined:
    Dec 18, 2019
    Posts:
    3
    So I am working on a project I am making (for school), it's a tower defense game where the cursor is supposed to be a crosshair texture. However I started noticing that my custom cursor alone is not the cause, even cursors used from internet have this problem which leaves me to believe something is wrong with the mouse/position itself.

    I have attempted to draw a reference so you kind of understand what I am trying to imply:

    I have also started to notice that after a bit the images become completely distorted for no reason (maybe I did something wrong who knows). But these are honestly the main issues I am facing right now. I hope I gave enough information for anyone feeling nice enough to help me out.
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @bommes21

    "I hope I gave enough information for anyone feeling nice enough to help me out."


    TBH, you didn't give anything else than description of what kind of problem you have.

    "...leaves me to believe something is wrong with the mouse/position itself."

    Getting mouse position works just fine in general, so it must be something in your code.

    You should show your code, screenshots of your scene setup, and in general, explain what exactly have you actually done? Did you use sprites or GameObject, what colliders you used or did you use the uGUI UI system? How did you get your cursor position and so on...
     
    Last edited: Jan 23, 2020
  3. bommes21

    bommes21

    Joined:
    Dec 18, 2019
    Posts:
    3

    The thing is the only code I use for the mouse is cosmetics at most. I had a script which I discarded because I became frustrated. I used both sprites and cursor texture modes because I wanted to see if it made a difference. It sadly did not.

    I never actually requested the cursor position, what I do recall doing is setting the transform position of the sprite to the mouseposition, unsure if the sprite is at fault or I am. I sadly cannot retrieve the script, it wasn't too complicated however and I followed a youtube tutorial:
    (for reference). Neither method sadly worked as hoped, but I used the second method (starts at 2:38). I hope this can shed some more light on the problem.
     
  4. danil00734

    danil00734

    Joined:
    Nov 4, 2019
    Posts:
    19
    If it's still a thing, if you're using SetCursor there is a parameter called "hotspot" which is exactly responsible for click area and you can modify its position, by using
    Code (CSharp):
    1. new Vector2(x, y)
    https://docs.unity3d.com/ScriptReference/Cursor.SetCursor.html
    Maybe it'll help to those who will find this thread later
     
    sunstriderko and BobberooniTooni like this.