"Laggy" mouse behaviour

Started by
3 comments, last by cozzie 10 years ago

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

Advertisement


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.

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.

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

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

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement