x


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

more ▼

asked Dec 08 '10 at 03:09 PM

raul corrales gravatar image

raul corrales
268 25 28 34

Please don't shout.

Dec 08 '10 at 03:37 PM skovacs1
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered Dec 08 '10 at 03:57 PM

skovacs1 gravatar image

skovacs1
10k 11 25 91

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??

Dec 09 '10 at 06:17 PM raul corrales

??? 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.

Dec 09 '10 at 06:43 PM skovacs1
(comments are locked)
10|3000 characters needed characters left

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??

more ▼

answered Dec 09 '10 at 03:25 AM

raul corrales gravatar image

raul corrales
268 25 28 34

Don't post comments as answers.

Dec 09 '10 at 03:56 AM Eric5h5
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Apr 08 '11 at 02:30 PM

Bampf gravatar image

Bampf
5k 8 19 49

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x983
x154
x32

asked: Dec 08 '10 at 03:09 PM

Seen: 1369 times

Last Updated: Dec 08 '10 at 03:09 PM