Least Laggy PlayerMoveEvent

Discussion in 'Plugin Development' started by Deleted user, Jan 19, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Deleted user

    I'm making a plugin to pretty much make player1 be in player2's shoes

    What I'm using now (Just raw backbone code here):
    Code:
    public void onMove(PlayerMoveEvent e){
      // Player p2 is define (for the sake of readability)
      Player p = e.getPlayer();
      p2.teleport(p.getLocation);
    }
    This is SUPER SUPER laggy...any way around this?
    Can I make it teleport more, but lag less?
     
  2. Offline

    Gater12

    If only the smooth teleporting feature in that one snapshot was here...
     
  3. Offline

    morshu9001

    Seems like Bukkit's teleport method is just too slow. What you could do instead is teleport the first time, then afterwards, do p2.setVelocity(p.getVelocity()). I'm not sure how accurate that will be; you might have to teleport every 30 seconds or so in case it goes out of sync.
     
  4. Offline

    Deleted user

    morshu9001 Gater12
    I need a more async and less async way of doing this -_-
    Maybe a custom event
    Check if a player moves and is beingfollowed
     
  5. Offline

    Nosliw

    If it looks a bit too jerky, you could check if the player has moved an entire block before teleporting, this will make the player teleport a lot less, and it could be more visually appealing?
     
  6. Offline

    Deleted user

    Nosliw
    Less appealing :(

    How would. I make a move event to check every move with a certain paramater?
     
  7. Offline

    Compressions

    JHG0
    Code:
    if(event.getTo().distance(event.getFrom()) > 1) {
    //player moved over 1 block
    }
     
  8. Offline

    Deleted user

    Compressions
    Need it to look smooth w/ little to no lag

    And I this .distanceSquared is quicker

    JHG0
    If you need it to look smooth, you need to use vectors, normal cancellation and location setting will cause the player to jerk.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 19, 2021
  9. Offline

    Garris0n

    The "smoothest" way is to give them a slowness potion, but that will screw with their FOV. Either way, you have to be wary of people using modified clients to get out of slowness/velocity changes because they're client-sided.
     
  10. Offline

    morshu9001

    I don't think that'll work properly. That's only if the player moves one entire block within one move event, which can probably only happen if he's moving very quickly. He could check if any of the coordinates are whole numbers by modding by 0.1.
     
  11. Offline

    Maximvdw

    Also note that the playermoveevent also triggers when just looking around. So excluding yaw and pitch from location might make it smoother.
     
  12. Offline

    maciekmm

    Try something along these lines - UNTESTED
    Code:java
    1.  
    2. event.getPlayer().setVelocity(new Vector(0,0,0));
    3. if (event.getFrom().getBlockX() == event.getTo().getBlockX()
    4. && event.getFrom().getBlockY() == event.getTo().getBlockY()
    5. && event.getFrom().getBlockZ() == event.getTo().getBlockZ()) {
    6. return;
    7. }
    8. event.setTo(event.getFrom()); //For hacked clients
     
  13. Offline

    morshu9001

    Wait, why are you setting the player's velocity to 0? That's the player he's trying to follow.
     
  14. Offline

    maciekmm

    Lol i completely posted it in wrong topic.
     
  15. Offline

    Deleted user

  16. Offline

    Syd

    Have you tried to "ride" the target player using the setPassenger() method?

    It should be pretty smooth, but maybe not suiteable for your needs.
     
  17. Offline

    Deleted user

    Syd
    Stacks players -_-
     
  18. Offline

    Syd

    Thats the point. :p

    It allows you to follow a player without pressing any key and might be a suitable base for what you want, as the teleport methods seems too laggy.
    You might get some extra stuff done in order to have a full following experience.
     
  19. Offline

    Deleted user

    Syd
    I wonder if I could set them as a passenger...and lower their position by <playerheight>

    Syd

    Wonder if you can do that

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  20. Offline

    Syd

    Maybe you can with a few tricks involving packets and such stuff, but I can't help you with it, I just wanted to throw this idea into the room. Fleshing it out would be your job.
     
  21. Offline

    Deleted user

    Check out iControlU
     
  22. Offline

    Syd

    JHG0
    In case you didn't follow the lastest development news of minecraft:
    In 1.8. you'll be able to "spectate" players. :)
     
  23. Offline

    Deleted user

Thread Status:
Not open for further replies.

Share This Page