Player.setVelocity() locked to 4.

Discussion in 'Spigot Plugin Development' started by devcexx, Jul 13, 2015.

  1. I was trying to do a simple plugin that when you press a pressure plate, it will give you speed in the Y-axis.
    So, this is my code:

    Code (Text):
    @EventHandler
        public void onInteract(PlayerInteractEvent e){
            if (e.getAction() == Action.PHYSICAL)
                Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                   
                    @Override
                    public void run() {
                        e.getPlayer().setVelocity(new Vector(0.0, 4.0, 0.0));
                    }
                },1L);
            }
    It works fine. But if I try to increase that 4.0 it will give me the same velocity as if I put 4.0.
    My question is: Is there some config in spigot that should I change or is there anything I've made wrong...?
     
  2. maybe there is a limit?
     
  3. Maybe but how to remove it xD?
     
  4. delayed task (1 tick)?

    setVelocity -> delay 1 tick -> setVelocity

    enjoy
     
  5. Mmmm, there isn't a limit. If you set more than 4 would work, try to put integer "new Vector(0, 373, 0)". On my code work fine
     
  6. Something like this?

    Code (Text):
    @EventHandler
        public void onInteract(PlayerInteractEvent e){
            if (e.getAction() == Action.PHYSICAL){
                e.getPlayer().setVelocity(new Vector(0.0, 10.0, 0.0));
                Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                 
                    @Override
                    public void run() {
                        e.getPlayer().setVelocity(new Vector(0.0, 10.0, 0.0));
                    }
                },1L);
    }
            }
     
  7. I tried it an it still doesn't work. I have to say that I'm using Spigot 1.8.7 i don't know if it has some relation
     
  8. Ok, I think I've found the limitation in Spigot 1.8.7:

    Code (Text):
    public PacketPlayOutEntityVelocity(int i, double d0, double d1, double d2) {
            this.a = i;
            double d3 = 3.9D;

            if (d0 < -d3) {
                d0 = -d3;
            }

            if (d1 < -d3) {
                d1 = -d3;
            }

            if (d2 < -d3) {
                d2 = -d3;
            }

            if (d0 > d3) {
                d0 = d3;
            }

            if (d1 > d3) {
                d1 = d3;
            }

            if (d2 > d3) {
                d2 = d3;
            }

            this.b = (int) (d0 * 8000.0D);
            this.c = (int) (d1 * 8000.0D);
            this.d = (int) (d2 * 8000.0D);
        }
    The maximum value of the speed in any axis should be 3.9 because the value of the velocity is multiplied by 8000 and is sent as a short value, so the maximum value can be aprox 32000
     
    • Like Like x 1
  9. You could simulate the velocity by teleporting the player higher manually... Might be laggy.
     
  10. I solved the issue making some scheduled task to set the player speed to the max with a bit of delay among them. Thanks for the help ^^
     
  11. Or you can remove the limitation becouse it is server-side.
     
  12. Nope because in that class, the server will send and client is expecting to receive short values. For that, the client is expecting to receive about 10 bytes (int + short + short + short). If you try to send more, the client packet decoder will raise an exception that the client has received too many bytes, and it will disconnect it from the server.
     
  13. about limitation...
    You can't remove it, because minecraft can't handle entity that move faster than 4 blocks per tick.
    Minecraft will need teleport entity instead of moving it.
     
  14. Players have terminal velocity like all other objects. You can inject into the server to fix this. It's not done at the packet level. Look at the Native varibles like MotX.