# My mouse pointer is slow

 0 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 268 ● 25 ● 28 ● 34 Please don't shout. Dec 08 '10 at 03:37 PM skovacs1 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 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?? more ▼ answered Dec 09 '10 at 03:25 AM raul corrales 268 ● 25 ● 28 ● 34 Don't post comments as answers. Dec 09 '10 at 03:56 AM Eric5h5 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 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 5k ● 8 ● 19 ● 49 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x983
x154
x32

asked: Dec 08 '10 at 03:09 PM

Seen: 1369 times

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