Player velocity returning strange values

Discussion in 'Plugin Development' started by SaxSalute, May 7, 2015.

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

    SaxSalute

    I'm trying to simply get a player's velocity vector. I'm calling playerObject.getVelocity(), and just to check the values I'm printing them out. The values are always very, and the X and Z values are always 0 unless I'm in the air. More than that, when I'm on the ground, my Y velocity reads as a small negative number. What's the deal with this?
     
  2. Offline

    Zombie_Striker

    What update are you using? I think it's a problem with the version of Bukkit you have.

    From what I can guess, the y is caused by the player constantly trying to go into the ground, while the XZ is a bug from the version you're using.
     
  3. Offline

    SaxSalute

    I've tried with Bukkit 1.8R1 and Spigot 1.8.3. Both ways it exhibits the same behavior.
     
  4. Offline

    SaxSalute

    I'm still having major issues with this. Does anybody have any ideas?
     
  5. Offline

    Konato_K

    @SaxSalute I believe that's the intended behavior of Entity#getVelocity?

    Anyway, what are you trying to do, maybe there is a different solution other than using this specific vector.
     
  6. Offline

    SaxSalute

    I'm trying to reduce knockback by scaling player velocity after a hit.

    Code:
    @EventHandler
        public void onDamage(EntityDamageEvent event) {
            final Entity damaged = event.getEntity();
            final SGPlayer p = getKitPlayer(damaged, this);
    
            //If the player is a Berserker
            if (p != null) {
                Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(MinecadeSG.getPlugin(), new Runnable() {
                    @Override
                    public void run() {
                        float multiplier = 1;
                    
                        System.out.println(damaged.getVelocity());
                        Vector knockback = damaged.getVelocity().multiply(multiplier);
                        damaged.setVelocity(knockback);
                    }
                }, 1L);
            }
        }
    I know that won't scale knockback, but that's what I was testing. What it's doing is freezing players in place on hit because the velocity it gets is 0 in X and Z.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
Thread Status:
Not open for further replies.

Share This Page