Jump to content

Player motionX always 0?


coolAlias

Recommended Posts

I was trying to do something when the player is moving only to find that player.motionX/Y/Z always seem to be zero on the server. I'm using the following method from within LivingUpdateEvent:

public static boolean isPlayerMoving(EntityPlayer player) {
  player.addChatMessage("Side == client? " + player.worldObj.isRemote);
  // always prints zero on server side; correct values displayed client side
  player.addChatMessage("Player motionX " + player.motionX + ", motionZ " + player.motionZ);
  return player.motionX != 0 || player.motionZ != 0;
}

I looked through NetServerHandler where it handles movement packets, and it uses player.motionX/Y/Z to calculate some things there, suggesting they shouldn't be zero even on the server; I suspect they get reset to zero sometime after the packet is handled, but I can't seem to find where.

EDIT: Looks like it happens in Entity's moveEntity method, which is called directly during the handling of the movement packet.

 

Anyone know a way I can detect if the player is in motion while on the server side?

Link to comment
Share on other sites

Hi

 

I don't know of a direct method.  There is a Packet27PlayerInput - Transmit the current state of the player movement - but I think it's only used for riding at the moment.

 

Two suggestions (which might or might not work depending on what you are trying to do and how responsive it needs to be)-

Use the ITickHandler on the server to record the player's position every tick, compare it to the last position to see whether the position has changed much.  But that might not work properly if the network is a bit laggy.  Depending on what you need to know, it might be ok if you can smooth it out (say - over a second).

Alternatively, you could add some code on the client side that sends custom packets to the server when the player moves (when the player is holding down a movement key) and when they stop moving (release all movement keys).

 

-TGG

Link to comment
Share on other sites

motionX/Y/Z is no longer used.

 

Use

moveForward and moveStrafing

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.

Link to comment
Share on other sites

TGG - thanks for the ideas, I'll try checking for the movement keys and send a packet, see how that works.

 

Draco - What do you mean motionX/Y/Z is no longer used? It's still in the code from what I can see (1.6.4). I did try using moveForward/Strafing like you suggested instead of the motion values, but they are still zero on the server, just like motion. Nice idea though.

Link to comment
Share on other sites

Draco - What do you mean motionX/Y/Z is no longer used?

 

It's what I've heard, that they were depreciated in favor of move/strafe.

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.

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.