A
A
Andrey Andryushchenko2015-03-31 13:42:02
Java
Andrey Andryushchenko, 2015-03-31 13:42:02

What parameters should be passed to the step method of the World object?

I'm writing a game in Java using the box2d physics engine. To calculate the physical interactions of bodies, I use a separate thread in which I call the step method on my instance of the World class. In the run method of this thread, I call step in an infinite loop and a few more methods necessary for additional calculations. The problem is that different times pass between different iterations of the loop, depending on the situation, because of this, the speed of movement of objects looks different. They either fly at breakneck speed, then they all slow down sharply. And if you transmit a different time each time, depending on how much time has passed since the last iteration, then the speeds of moving objects change.
It is also not clear what values ​​to pass as the second and third parameters. If you transfer very large parameters, then everything starts to lag terribly, and if you transfer small parameters, then sometimes the accuracy of the calculations is not enough.
In general, I'm completely confused about what should be passed as parameters to the step method and where and how to call it...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniil Petrov, 2015-04-03
@delphikettle

In step, pass a constant value and then do not call it until the sum of 'deltas' exceeds this very value.
After each step, you can block the physics thread until another thread draws (or do something else, but you should have >=1 draw for each step). For example, I do this through the usual wait / notify.
See the other two arguments for yourself. I have 15 and 30. I'm not complaining, although this may even be too much.

D
Daniil Basmanov, 2015-03-31
@BasmanovDaniil

There are many solutions, but I would advise to separate the physics from the graphics. Consider physics at regular intervals, then the movement of objects will not be ragged. I advise you to read about game cycles here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question