Search Unity

Question Screen distortion effect versus custom cursor object

Discussion in 'Editor & General Support' started by dashofrainbow, Feb 25, 2024.

  1. dashofrainbow


    Jan 23, 2024
    Hello all, I have a visual effect (not created by me) that I apply onto the game screen via attaching a script to the main camera. This works fine and all objects in the scene have the desired look. I also have a cursor I would like to display the same way, so instead of using Project Settings > Player to define a cursor, I create an object that follows the mouse. It works, but the visual effect I want to use has some distortion on it (fisheye) that messes with the alignment at the edges of the screen. Unless I can figure out how to compensate, this results in the "cursor's hotspot" not lining up with what the player is actually clicking on, resulting in mis-clicks. I am not currently knowledgeable enough to reverse engineer the visual effect to understand what to do about this, nor am I interested in removing the fisheye part of the effect.

    Any advice?

    In case it is relevant, here is the code I use for the object-based method. It is fairly simple and works, but becomes less accurate at the edges of the screen due to the visual effect's distortion.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    5. public class cursorMovement : MonoBehaviour
    6. {
    7.     [SerializeField]
    8.     private float xOffset;
    9.     [SerializeField]
    10.     private float yOffset;
    12.     void Start()
    13.     {
    14.         Cursor.visible = false;
    15.     }
    17.     void Update()
    18.     {
    19.         Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    20.         mousePosition.x += xOffset;
    21.         mousePosition.y += yOffset;
    22.         transform.position = mousePosition;
    23.     }
    24. }