Jump to content
  • Advertisement
Sign in to follow this  
Gorbstein

Consistent mouse<->physics behaviour across machines

This topic is 2742 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

Having a problem with my input, where the forces obtained from the mouse are not obtaining the same results when pushed into my (very simple) physics system, when run on slower/faster machines, or even just when I enable vsync.

The game is 2D top down. I'm using the delta X movement of the mouse per frame to add a rotational force to my spaceship.

So it looks something like this:


In my input component:

void playerControl()
{
float deltaX = input->getMouseXDelta();
physics->addRotationForce(deltaX);
input->clearMouseDeltas();

...the rest of the input...
}


in my physics component.......

void addRotationForce(float amount)
{
rotationForce+=amount;
}

//then on each timestep
void onUpdate(float deltaTime)
{
//apply forces
rotationalAcceleration = rotationForce / mass;
rotationalVelocity += (rotationalAcceleration * deltaTime);
heading += rotationalVelocity * deltaTime;

//simple friction
rotationalVelocity += (rotationalFriction*-rotationalVelocity*deltaTime);

//reset forces
rotationForce=0;
rotationalAcceleration = 0;

..other physics stuff...

}




When I enable vsync or run on a slower machine, the mouse inputs seem to get massively multiplied and the ship spins too fast.

The input is coming from an Irrlicht device, which takes the windows mouse movement messages and adds them to a deltaX, then resets the cursor to screen centre. As you can see I reset the deltas every time I read them above.

It seems to me the physics isn't producing the same output when the mouse input forces are supplied in lots of small, frequent values (ie: when running at 500fps) when compared with far less, larger values (ie: running at 60fps with vsync).

I'm guessing the smaller, more frequent values may be getting 'eaten up' by the friction?

What am I doing wrong?

TIA
D

Share this post


Link to post
Share on other sites
Advertisement
Hmm as usually happens, I spend hours working on this, then I solve it as soon as I post a message here......


Changed...
rotationalVelocity += (rotationalAcceleration * deltaTime);

To..

rotationalVelocity += rotationalAcceleration;

And this seems much better.

I'm guessing since the mouse movements will automatically be smaller for a smaller timestep that I shouldn't be factoring in DT here. I should only use that for keys that are pressed across frames...

D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!