Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Velocity of other entities don't get updated correctly #3289

Open
1 task done
zardoy opened this issue Jan 22, 2024 · 8 comments
Open
1 task done

Velocity of other entities don't get updated correctly #3289

zardoy opened this issue Jan 22, 2024 · 8 comments
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f

Comments

@zardoy
Copy link
Contributor

zardoy commented Jan 22, 2024

  • The FAQ doesn't contain a resolution to my issue

Versions

  • mineflayer: latest 4.18.0
  • server: vanilla/spigot 1.18.2
  • node: 1.18.2

Detailed description of a problem

Velocity of other entities don't get updated in some cases. For example if you push another player the bot.entities["id"].velocity.z or x won't be 0 even if it stays on the same place. However bot.entity.velocity does always seem to work correctly. Is this a known limitation?

@zardoy zardoy added possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f labels Jan 22, 2024
@rom1504
Copy link
Member

rom1504 commented Jan 22, 2024

entity.velocity.update(conv.fromNotchVelocity(notchVel))
update is happening there

Idk if there are other packets or if the client is supposed to run the physics based on previous positions

@GenerelSchwerz
Copy link
Contributor

I did some looking into this and entities are updated via rel_entity_move, which provides the positional data and not velocity iirc.

@zardoy
Copy link
Contributor Author

zardoy commented Jan 22, 2024

entities are updated via rel_entity_move, which provides the positional data and not velocity

And also stable api does not fire any event in this case so it's unclear how to get an event of updating the velocity

@rom1504
Copy link
Member

rom1504 commented Jan 22, 2024 via email

@GenerelSchwerz
Copy link
Contributor

entities are updated via rel_entity_move, which provides the positional data and not velocity

And also stable api does not fire any event in this case so it's unclear how to get an event of updating the velocity

That isn't completely true:

bot._client.on('rel_entity_move', (packet) => {
exposed "entityMoved" that would allow you to calculate the velocity differential. However, I recall attempting to do what you are trying to do; this event fires every 100ms, meaning velocity cannot be correctly calculated per tick.

@zardoy
Copy link
Contributor Author

zardoy commented Jan 23, 2024

exposed "entityMoved" that would allow you to calculate the velocity differential. However, I recall attempting to do what you are trying to do; this event fires every 100ms, meaning velocity cannot be correctly calculated per tick.

Sorry I didn't notice that question was for me. I wanted it to use to display entities with different colors based on its velocity (like idle, walking or sprinting) on minimap. entityMoved would be enough for me if I could get the correct velocity of any entity. Or you mean I should calculate it myself by using this event?

@GenerelSchwerz
Copy link
Contributor

exposed "entityMoved" that would allow you to calculate the velocity differential. However, I recall attempting to do what you are trying to do; this event fires every 100ms, meaning velocity cannot be correctly calculated per tick.

Sorry I didn't notice that question was for me. I wanted it to use to display entities with different colors based on its velocity (like idle, walking or sprinting) on minimap. entityMoved would be enough for me if I could get the correct velocity of any entity. Or you mean I should calculate it myself by using this event?

To my knowledge, and I have tried pretty extensively at doing what you described (see https://github.com/nxg-org/mineflayer-tracker), it is impossible to get an accurate velocity of entities server side without interpolation that would constantly need to be corrected. (Namely for players, their yaw/pitch cannot be predicted). You can use the average positional changes you receive from entityMoved to create your own pseudo-velocity that would be able to differentiate between standing, walking, and moving, but you cannot use it to predict the next physics step forward of server entities.

If you have questions about the code I linked (as it has no README), I can explain what I do to predict probable velocities of entities given in the discord.

@zardoy
Copy link
Contributor Author

zardoy commented Mar 5, 2024

I forgot to say that I've successfully integrated your module but it allows you only to get the approximate velocity and still don't understand how to get the state of the player (e.g. walking, sprinting and so on)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f
Projects
None yet
Development

No branches or pull requests

3 participants