notgiven688 / jitterphysics

A cross-platform, realtime physics engine for all .NET apps.
MIT License
386 stars 87 forks source link

Running the physics on a Windows Form application, timestep and other problems #12

Closed ramonfr2016 closed 3 years ago

ramonfr2016 commented 7 years ago

Hi, I'm running the physics on a Windows Form application. The application is just a server, so it doesn't need to render any game object. It just calculates the positions and collisions then sends the numbers to the clients, who will render the objects.

As we all know, every game API or engine has an Update() method. However, I'm not sure where to call world.Step() on a Windows Form app.

Currently, I'm using a System.Timers.Timer object, and trying different intervals. But the physics behaviour looks weird depending on the interval value.

In my server, so far, I have just a bouncing ball and a ground.

At 1 ms, the ball often doesn't bounce when hitting the ground.

At 15 ms, the ball often doesn't bounce, and it seems slower.

At 30 ms, the ball bounces with a force lower than expected.

The time step call happens at every clock tick, as the following:

Step(1.0f / 100.0f, false);

When and how often should I call Step() on a Windows Forms app?

notgiven688 commented 3 years ago

Step(1.0f / 100.0f, false); integrates your world 10ms forward in time. It should not matter if you call that function every 10ms (that should then be real time) for a second (the simulated second would then be in real-time) or call that function each day at midnight for 10 days.

Your other questions (Windows Forms) are not related to the engine.