- Home /
How to stop lag between Vectrosity circle and GUI.Label at mouse cursor?
I am using Vectrosity to draw a circle at the mouse location, and then would like to draw text in the center of it. I'm using GUI.Label to draw the text. The problem is that the Vectrosity circle is lagging behind the GUI.Label when the mouse is moving. The faster you move it, the more it's off; to the point of being outside the circle. How do I make sure that these are in the same location? Note that this also happens when using "Input.mousePosition" rather than "Event.current.mousePosition".
Here's a simplified example, and a screenshot of what I see:
using UnityEngine;
using System.Collections;
using Vectrosity;
public class TestMouse : MonoBehaviour {
private VectorLine rings;
// START
void Start()
{
// Vectrosity Lines & Points; Drawn later with MakeCircle
rings = new VectorLine("Ring1", new Vector2[32], Color.white, null, 4, LineType.Continuous);
}
// GUI
void OnGUI ()
{
float mousex = Event.current.mousePosition.x;
float mousey = Event.current.mousePosition.y;
// Ring
rings.MakeCircle(new Vector2(mousex, Screen.height - mousey), 30);
rings.Draw();
// Draw text
Vector2 textSize = GUI.skin.label.CalcSize(new GUIContent("Test"));
GUI.Label ( new Rect(
mousex - (textSize.x / 2),
(mousey - 15),
textSize.x,
20),
"Test"
);
}
}
I am also having this issue, only I am using it in a raycast.
I cast a ray from the camera a point in the world, where the mouse position is, and base my character rotation and a GUI element on this hit position.
The problem is, it lags behind when the mouse is in motion, as though it is taking the previous mouse position, rather than the current.