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

Small movements may not trigger PlayerMoveEvent until the player rotates #6590

Open
minijaham opened this issue Dec 30, 2024 · 3 comments
Open
Labels
Category: API Related to the plugin API Opinions Wanted Request for comments & opinions from the community Status: Debugged Cause of the bug has been found, but not fixed

Comments

@minijaham
Copy link
Contributor

minijaham commented Dec 30, 2024

Plugin information

Bug happens without plugins

Problem description

Steps to reproduce:

  1. Listen for PlayerMoveEvent
  2. Write code to dump X and Z coordinates of PlayerMoveEvent::getFrom() and PlayerMoveEvent::getTo()
  3. Don't move, but only rotate the player

Plugin Code

public function onPlayerMove(PlayerMoveEvent $event) : void
{
    $player = $event->getPlayer();

    $from = $event->getFrom()->asPosition();
    $to   = $event->getTo()->asPosition();

    var_dump("FROM");
    var_dump($from->x);
    var_dump($from->y);
    var_dump($from->z);
    
    var_dump("");

    var_dump("TO");
    var_dump($to->x);
    var_dump($to->y);
    var_dump($to->z);
}

Results
string(4) "FROM"
float(-829.7068)
float(67)
float(1219.9551)

string(2) "TO"
float(-829.7025)
float(67)
float(1219.9567)

As you can see, there are subtle differences in the player's X and Z position.

I'm not entirely sure if this is an expected behavior, though. I have performed some researches, but couldn't find an issue related with this behavior specifically.

Expected behaviour

The X and Z position should be the same when rotating the player.

PocketMine-MP version

5.23.2

PHP version

8.2.17

Server OS

win

Game version (if applicable)

Windows

@dktapps
Copy link
Member

dktapps commented Dec 30, 2024

It's probably because of this:

if($delta > 0.0001 || $deltaAngle > 1.0){

There can be a difference in position unreported by PlayerMoveEvent if the distance is below 0.01 blocks. Rotation bypasses this check since PlayerMoveEvent reports both position and rotation.

It's definitely not ideal behaviour but I'm not sure how it could be done better. The reason it's done this way is to make sure we aren't spamming the event whenever a player sends any movement at all.

@dktapps dktapps changed the title Change in yaw / pitch also changes the X and Z value of a location. Small movements may not trigger PlayerMoveEvent until the player rotates Dec 30, 2024
@dktapps dktapps added Category: API Related to the plugin API Status: Debugged Cause of the bug has been found, but not fixed Opinions Wanted Request for comments & opinions from the community labels Dec 30, 2024
@dries-c
Copy link
Member

dries-c commented Dec 30, 2024

Ideally the event listener would specify how precise they want the event to change before getting called (for example allow only vector3 movements without rotation etc). But that's hard to deal with on the PM side. You would expect all rotations to call a PlayerMoveEvent regardless of how much they move.

@dktapps
Copy link
Member

dktapps commented Dec 30, 2024

I've considered splitting it into two events before. But I doubt it would have much benefit (and might have negative consequences in stuff like PvP servers).

Perhaps what we need to do is just always dispatch an event if there was no new movement processed on the current tick, so that plugins always have the latest position.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: API Related to the plugin API Opinions Wanted Request for comments & opinions from the community Status: Debugged Cause of the bug has been found, but not fixed
Projects
None yet
Development

No branches or pull requests

3 participants