Jump to content

[1.7.2] Apply Vertical Motion When Jumping (Double Jumping)


TLHPoE

Recommended Posts

I'm currently attempting to add double jumping, and I have everything else sorted but the actual jumping. I recently discovered the fact that you can add all the motion you want when the player is jumping, but the motion will only start to take place when he hits the ground.

 

For example, while the player is air borne, I add 10 to motionY. It doesn't affect the player, until the player hits the ground. At that point, the player flies into the air like a rocket.

 

Here's my code:

		double amt = 1;
		if(player.motionY < 0) {
			amt += (player.motionY * -1);
		}
		player.addVelocity(0, amt, 0);

Kain

Link to comment
Share on other sites

I'm a little puzzled by your code.  When are you call this code?

 

If you're calling this on every tick while in the air then it would have a really odd effect.  So I'll assume you're calling this from a key input handler for spacebar?

 

Default jump (with no potion effect) is motionY = 0.42D  Note that it is a positive value.  It of course reduces during the course of the jump, and then becomes negative during the falling part of the jump.  Since you're testing for negative motionY, I'm assuming you want the double jump effect to only operate if the player has already crested in the first jump, which is fairly typical.

 

So let's say that the motionY = -0.2D when you run your code.  amt value will become 1.2 then you'll add velocity where the 0.2 will cancel and you'll effectively add an upwards motionY = 1.0D.

 

So the code makes sense to me.  I just wanted to trace it through...

 

Therefore, I believe it may be some other issue.  Like maybe a client versus server thing.  If you're handling the key input event I suspect that occurs on the client side, but the motion should be controlled by the server side.  So maybe this is a client-server sync issue?  Only thing I can think of.  To test this, you might want to add some System.out.println() statements to indicate which side the code is running on and to print out the motionY value on each side.

 

If the problem is indeed related to client-server sync, I think that what you would do is instead of running this code directly, your key input event would send packet to server and the server would run this code in response to receiving the packet.

 

Just a suggestion.

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

Link to comment
Share on other sites

I should be on server side. The code I posted would be in my LivingJumpEvent, which I cancel with my own method, and then I call the event from a packet that was sent from the client.

 

I'll go see if it's trying to set anything in the client.

Kain

Link to comment
Share on other sites

Ok, the initial jump is on both sides, but it seems that motion only takes effect on the client side? I'm using packets so it's only going to be called on the server side.

 

So should I also call it on the client side?

Kain

Link to comment
Share on other sites

I'm checking the keyboard in a player tick event on the client.

 

package ttm.handler.event;

import org.lwjgl.input.Keyboard;

import ttm.Reference;
import ttm.network.PacketMessage;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;

public class FMLClientEventHandler {
private boolean canJump = true;

@SubscribeEvent
public void playerTick(TickEvent.PlayerTickEvent event) {
	if(Keyboard.getEventKey() == Keyboard.KEY_SPACE) {
		if(canJump && Keyboard.getEventKeyState()) {
			new PacketMessage(Reference.PacketMessages.JUMP).sendToServer();
			canJump = false;
		} else if(!canJump && !Keyboard.getEventKeyState()) {
			canJump = true;
		}
	}
}
}

Kain

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.