Jump to content

1.18 Delta Time variable


FoxBox

Recommended Posts

How to get DeltaTime variable?  I tried to take one from the Minecraft instance and multiply by 3 (because the default is not 60 but 20 fps). This works, except that with shaders the variable becomes several times larger and the animations become too fast.

Edited by FoxBox
Link to comment
Share on other sites

  • FoxBox changed the title to 1.18 Delta Time variable

Minecraft uses what's known as a partialTick which is some value between 0-1 that represents the frames between the previous tick and the current tick. Typically, you would have the original position and the new position, and then linearly interpolate using the partialTick (usually via `Mth#lerp`). The partialTick is provided in nearly all rendering methods as a float.

Link to comment
Share on other sites

I tried to do it like this, but with shaders the animations are 2x faster..

private static long LAST_TIME = 0;
public static float DELTA_TIME = 0;

@SubscribeEvent
public static void onRenderTick(TickEvent.RenderTickEvent event) {
        if (event.phase == TickEvent.Phase.START) {
            final long time = Util.getNanos();
            DELTA_TIME = (time - LAST_TIME) / 16666666F;
            LAST_TIME = time;
        }
}

Edited by FoxBox
Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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