Jump to content

  • Log In with Google      Sign In   
  • Create Account

"Laggy" mouse behaviour


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 sharepointme   Members   -  Reputation: 111

Like
1Likes
Like

Posted 31 March 2014 - 02:42 AM

Hi all,

 

I have an issue in my game. I need some ideas about my approach.

 

I am currently having a gameloop with fixed time step. When I am rendering I always have the current state and previous state available. In order to render "in-between-states" I always render one update back in time by using this formula:

 

pos = current_state * alpha + last_state * (1 - alpha).

 

where alpha amount (fraction) that I have passed current_state (I hope it makes sense this far biggrin.png).

 

...all this works well when rendering - everything is nice and smooth. The issue is the mouse! I have trouble wrapping my head around how to handle the mouse. At this point I handle the mouse in the exact same way. So I am getting the mouse position by interpolating based on last_state and current_state.... but the mouse "feels" laggy (it is smooth though).

 

What is the best-practice approach? Do I need to grab the mouse position in the updates or the rendering part?

 

/simon


Edited by sharepointme, 31 March 2014 - 02:44 AM.


Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 7991

Like
1Likes
Like

Posted 31 March 2014 - 03:09 AM


So I am getting the mouse position by interpolating based on last_state and current_state.... but the mouse "feels" laggy (it is smooth though).

Try to decouple the mouse movement from the rendering. The mouse movement is in direct control of the user and any lag will be really obviously. Therefor I would sugguest to render always the current position of the mouse (no interpolation).

 

Still there is one issue you need to address. When the mouse interacts with your game, in other words, the mouse interacts with rendered content like buttons, then you need to synchronize this interaction with the rendered content. Eg when the user press a mouse button, you need to consider what was rendered at this moment on the screen at the mouse position, this is most likely an interpolation of your last and current frame.



#3 AgentC   Members   -  Reputation: 1413

Like
1Likes
Like

Posted 31 March 2014 - 05:12 AM

Another way is to split your updates into two categories: fixed step and variable step, or in Unity terms FixedUpdate() and Update().

 

Objects that are governed by the fixed step update would be interpolated, while the rest (particles, UI for example) would update every frame with a variable step, then render their latest state.

 

When the mouse also affects visible player character orientation (3rd person game) you'd need to override the player orientation in between fixed steps, so that there's no sync issues between camera / player character.


Every time you add a boolean member variable, God kills a kitten. Every time you create a Manager class, God kills a kitten. Every time you create a Singleton...

Urho3D (engine)  Hessian (C64 game project)


#4 fir   Members   -  Reputation: -456

Like
0Likes
Like

Posted 31 March 2014 - 06:06 AM

is there any reason why you got update frequenzy lower than drawing frame frequenzy?



#5 cozzie   Members   -  Reputation: 1762

Like
0Likes
Like

Posted 31 March 2014 - 09:02 AM

I get keyboard and mouse input in my main loop independent of rendering. This works for me. It may sound strange but you could double check if you have vsync enabled or not, if you change this and your input lag changes/ improves, then your bottleneck might be the dependency on rendering




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS