Jump to content

Direction Based Flight Help


Zethariel

Recommended Posts

Hello,

 

I'm trying to add a flight system that uses velocity rather than the stiff minecraft creative flight. I have managed to make a prototype that sort of works how I wanted it to, but it has two major flaws:

 

1. When the movement starts it propells the player once, waits for some ticks and then resumes moving. No idea why that happens

2. Pressing any other button causes the forward button to not be in a pressed state anymore, which shouldn't be the case...


Code:

@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onTestKeyPress(KeyInputEvent event){
		GameSettings settings =Minecraft.getMinecraft().gameSettings;
		EntityPlayerSP player = Minecraft.getMinecraft().player;
		
		if (settings.keyBindForward.isKeyDown()){
			settings.keyBindForward.unPressAllKeys();
			Vec3d vec = player.getLookVec().normalize().scale(2);
			player.setVelocity(0, 0, 0);
			player.addVelocity(vec.xCoord, vec.yCoord, vec.zCoord);
			player.setNoGravity(true);
		} else {
			player.setNoGravity(false);
		}
		
	}

 

I know it's very bad, but I only needed a proof of concept before pursuing this path any further. Is there perhaps a better way of doing this? What I basically want to do is:

1. Capture the key press for movement and disable it

2. Propell player in the direction of the movement key based on current camera look vector.

 

Any feedback is appreciated.

I do pony stuff :3

Link to comment
Share on other sites

You are going to want to use the ClientTickEvent and in there check if your key is down to apply movement every tick. KeyInputEvent should only be called every so often.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 hour ago, Animefan8888 said:

You are going to want to use the ClientTickEvent and in there check if your key is down to apply movement every tick. KeyInputEvent should only be called every so often.

Okay, thanks, I'll try that. KeyInputEvent will be called regardless of anything, and I have other things checking it as well.

 

EDIT: That didn't help any of the issues I described

Edited by Zethariel

I do pony stuff :3

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.

Announcements



×
×
  • Create New...

Important Information

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