- Home /
My mouse pointer is slow
Hi to all.
the speed of my mouse pointer slows. when the framerate is under sixty...
how can i put the speed of the mouse pointer in DELTATIME?
my actual code is
function OnGUI
{
var pos : Rect = Rect(mousePos.x,Screen.height - mousePos.y,64,64);
GUI.Label(pos,cursorImage);
}
thanks in advance
Answer by skovacs1 · Dec 08, 2010 at 03:57 PM
You question doesn't make sense. "put the speed of the mouse pointer in deltaTime" is complete nonsense. What is that even supposed to mean?
You cannot change the speed of your mouse in Unity. You can change the sensitivity in the Input Settings which affects the responsiveness of Input functions, but that's about it.
Unity is generally processing and doing other resource-consuming stuff when your framerate begins to drop. If this is sufficiently CPU-intensive, leaving less available CPU capacity for your computer's OS's input mechanism to deal with your mouse input, this could also cause your mouse to be less responsive in general, not just in Unity. It is also possible that some other process is using system resources, leaving less for Unity, making it in an equally CPU-intensive setup that yields the same results. Whatever the cause, the issue is likely not one with the mouse necessarily, but with what you are doing in-between each frame that causes your framerate to drop. You should fix that issue in stead as framerate issues are very problematic in and of themselves.
OnGUI is called several times per frame and should update more often that Update, meaning that it is happening more often than your framerate would indicate, but it is still limited by the same problems above. Time.deltaTime is the amount of time it took to complete the last frame and makes little sense outside of the context of an Update function which is called only once per frame. See the docs for more.
0
I refer that when the frames per second go down 60 my leader of the mouse finds it hard to him to continue to mouseX, and to mouseY..
is there any solution??
??? What? That sentence makes even less sense. If I make some wild assumptions about what this sentence is supposed to mean, it would seem like you are repeating your question "the speed of my mouse pointer slows when the framerate is under sixty", but that was never in doubt. Again, the part that makes no sense is "put the speed of the mouse pointer in deltaTime". Repeating your question in a more confused and broken English only serves to confuse the issue further.
Answer by raul corrales · Dec 09, 2010 at 03:25 AM
I refer that when the frames per second go down 60 my leader of the mouse finds it hard to him to continue to mouseX, and to mouseY..
is there any solution??
Answer by Bampf · Apr 08, 2011 at 02:30 PM
If I'm understanding you, you want to calculate the absolute speed of the mouse pointer, without getting bad effects from the frame rate. In other words, when the frame rate is worse, the mouse jumps further between frames, even though the speed of the movement is the same.
The speed of the mouse is simply: the position change divided by the time it took to move that far. So all you need to do is divide the position change by deltaTime.
This code isn't tested, its just to give you an idea:
var velocity; var speed;
if (Time.deltaTime > 0.0) { velocity = (newMousePos - oldMousePos) / Time.deltaTime; // velocity vector speed = velocity.Magnitude(); }
That's the theory, anyway. In practice, you may get noise and rounding issues. Simple example: if the frame rate is really fast, the timeDelta for some frames will be very very small, and the mouse pointer may not have moved to a new pixel. If you look at the velocity at just that one frame, you may think the mouse isn't moving.
If you are using the velocity every frame, then it's no big deal if the velocity rounds up or down each frame. But if you want to get the velocity at a single point in time, say when the player lets go of the mouse button, then you may need to average together the velocities of more than just the most recent frame.
Here's a link to similar Q&A on this topic, but for iOS drags rather than mouse pointer. Same idea though.