Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.5] player.setMotion() is not smooth enough


GrigLog
 Share

Recommended Posts

What Im trying to do is to implement a "dash" mechanic on a Shift button.
 

@SubscribeEvent
    public static void onEvent(InputEvent.KeyInputEvent event){
        KeyBinding runBinding = Minecraft.getInstance().gameSettings.keyBindSprint;
        int key = event.getKey();
        int runKey = runBinding.getKey().getKeyCode();
        ClientPlayerEntity player = Minecraft.getInstance().player;
        if (key == runKey){
            //some checks, and then:
            float yaw = player.rotationYaw;
            float x = -MathHelper.sin(yaw * 0.017453292F);
            float z = MathHelper.cos(yaw * 0.017453292F);
            double groundMotion = 5, airMotion = 2;
            if (player.isOnGround())
                player.setMotion(new Vector3d(x * groundMotion, 0, z * groundMotion));
            else
                player.setMotion(new Vector3d(x * airMotion, 0, z * airMotion));
        }
    }

And this code works. The problem is, it causes a lot of lag when the setMotion() is called - my fps drops from 60 to 50-40 and the dash movement looks discrete. I wonder why is it so and how it can be improved...

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.