- Home /
Making a GUI element follow the cursor without delay.
Hi all, I want to make a UI element (Several UI elements, actually) follow the mouse cursor without any delay.
If I just do something like
Image UIElement;
void Update(){
UIElement.transform.position = Input.mousePosition;
}
The UIElement follows the cursor, but if I move the cursor a bit fast it drags behind it a bit. Anyone know a solution?
And no, I cannot just set my element as a custom cursor (it is not actually the cursor, I just want it to always be next to it).
Is it more responsive if you move the transform to FixedUpdate()?
No, that doesn't seem to matter at all. I think the problem is basically that I can move my mouse during an update...
I guess a solution that would prevent you from really noticing the delay would be to not use a cursor as a cursor and just hide the cursor and draw a texture at mouse position - but it would still be slower than having an actual cursor and might feel a bit off...
Try building the project to PC and see if the final product still has the issue, it could be the editor or the profiler etc etc causing some lag.
As for the delay for disabling the cursor and using a texture I've done this a few times before and its generally felt fine.
Another thing you could do as a sanity check is to make a new empty project with just your cursor following code to make sure its not something else in your project slowing things down and creating a lag