Jump to content

Relationship between motionX, motionY, motionZ and player movement


RickK

Recommended Posts

Hello,

 

This question isn't really about modding any minecraft behavior so much as understanding it. I've been trying to figure out this problem for weeks on end to no avail. I've searched endlessly through the 1.8 and 1.9 MCP decompiles and even attempted to model this server-side, but no solution presents itself.

 

I know that the player's velocity is supposedly the vector composed of their motionX, motionY, and motionZ. Looking through the EntityLivingBase#moveEntityWithHeading function, it seems that these are multiplied by the friction of the block the player is standing on when they move (predictably). This makes sense when these actually represent the components of the velocity vector, but what confuses me is that these same variables are also passed into the Entity#moveEntity function, where they are treated as displacement rather than as velocity (the derivative of displacement). And the Entity#moveFlying function (which, strangely enough, is called even when the player isn't flying or even in the air) also treats these values like displacement.

 

Also, I see no mention of the motionX, motionY, and motionZ variables being set to anything when a player initiates movement, only multiplied. What determines their initial values / when they're incremented? Does this relate to the moveStrafe and moveForward values set by MovementInputFromOptions? Where are these variables translated into actual positions?

 

I'm also confused because the player's server-side velocity X and Z components are often zero, even though the player is moving, and based on everything I've found, the server-side velocity mirrors the client-side velocity as represented by motionX,Y,Z.

 

But my main question is: what is the relationship between these variables and the actual move displacement of the player? Any help or guidance would be immensely appreciated.

Edited by RickK
Link to comment
Share on other sites

Hi Rick

motionX, Y, Z are velocity, i.e. the movement per tick.

The position of the player is controlled from the server, not the client.   The client sends packets to the server telling it what the player is doing (CInputPacket).  The client position is periodically updated by a packet sent from the server to the client (eg SEntityTeleportPacket or SEntityPacket).

 

In 1.15.2 the CInputPacket sets moveStrafing and moveForward, which are copied to the motion during livingTick

Some of the methods where motionX, Y, Z are passed in are not actually displacements although they might look like it.  They are a displacement per tick.  So the tick method just adds the motionX because it has already been converted to the correct units

i.e.

x += deltaX;

where deltaX = motionX * time, however time = 1 (tick), so the code just says deltaX = motionX

i.e.

x += motionX;

-TGG

 

 

  • Thanks 1
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.