Sign in to follow this  

Smooth mouse motion

This topic is 4748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

At first I put the paddle exactly where the mouse was, but it was to fast. Then I thought to move the paddle in the same speed towards were the mouse was, I checked if the paddle were to the right or the left to the paddle and moved left or right acordingly the mouse were over the paddle I didn't move. But it doesn't feel good. I've seen people use a mouse sensitivity variable, but I havn't got it to work.

Hope it makes any sense at all, just out of bed =)

///walle

Share this post


Link to post
Share on other sites
You could use the frame time and multiply your mouse delta values by frame time and pixels per second, e.g.

static const float pixelsPerSecond = WindowHeight / 4.0;

int newY = mouseDeltaY * frameTimeInSeconds * pixelsPerSecond;

playerPaddle.SetNewY(newY);

Something along that line should be good, I guess. You don't even need to check every frame - sum up delta values until frameTime > threshold, with threshold being at least 0.02s (50 FPS) because sometimes movement will be jerky (e.g. abrupt position changes if frameTime varies too much).
To get it really smooth, you can sample the last 4 - 8 frames and interpolate frame times.

Good luck,
Pat.

Share this post


Link to post
Share on other sites
I can't really get it to work...it is for a breakout style of game, so I changed the window hight to window width and such...but the paddle just sitts at one corner all the time.
What did you mean with "frameTimeInSeconds"? How do you get it?

//walle

Share this post


Link to post
Share on other sites

This topic is 4748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this