Jump to content

Recommended Posts

Posted

So I added a variable timestep to my physics simulation, and I want to make the speed things move independent of server lag by changing the speed from 1/20 to how many ticks happened in the last second. Where does Minecraft keep these things?

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Posted

I've played with this before and like diesieben07 mentions it usually doesn't result in what you think -- you can fairly easily make the physics honor real time (I'll explain how below), but when everything else in the game is lagging it is really weird when the physics works real time. Basically it is just much more playable when everything lags together.

 

But, if you want to play around with it, you can use Java's System.nanoTime field to measure the time each tick is taking and adjust accordingly. Basically, you need a field to hold the result of System.nanoTime from the previous tick, and you need a field for the time for current tick. You can update these in the tick events (probably the client tick and server tick events) where you copy current time to the previous time, then update the current time from System.nanoTime.

 

Then you just need to compare what the tick took relative to what it should be. There is supposed to be 20 ticks per second so each tick should be 0.05 seconds = 50 miliseconds = 50,000 nanoseconds. So to adjust things for this lag, you would use a scaling factor of (currentTime - previousTime) / 50000.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Of course, I just record the system time the last time i ran the tick, and subtract the current time.

 

Better than rummaging through MC code anyway.

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Posted

Then you just need to compare what the tick took relative to what it should be. There is supposed to be 20 ticks per second so each tick should be 0.05 seconds = 50 miliseconds = 50,000 nanoseconds. So to adjust things for this lag, you would use a scaling factor of (currentTime - previousTime) / 50000.

 

Its not 50,000 nanos.  It's 50,000,000.  Mili, micro, nano.

 

https://en.wikipedia.org/wiki/Nanosecond

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.