Problems with vectors

Discussion in 'Plugin Development' started by Tartarnos, Jan 16, 2021.

  1. Offline

    Tartarnos

    Im trying to create a plugin that launches the player into the air when they take damage. The weird thing is, the player only seems to get launched when they're not touching the ground when they get hit by an entity, or when they take environmental damage (eg. fall damage, cactus damage, suffocation).

    I realize that that explanation isn't the best, so for example, if I stay still on the ground and let a zombie hit me, I won't get launched. If I press space and the zombie hits me while Im in the air, I get launched. Does anyone know the reason why this happens?

    Code:
    package com.Tartarnos.jump;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;
    
    public class Main extends JavaPlugin implements Listener {
    
        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
          
                        }
      
        @EventHandler
        public void onDamageTaken(EntityDamageEvent e) {
              
            if(e.getEntity() instanceof Player) {
              
            }
                e.getEntity().setVelocity(new Vector(0, 20, 0));
          
            }
      
        }
     
  2. Offline

    Zaary

    I will use
    e.getEntity().setVelocity(e.getEntity().getVelocity().setY(20));
     

Share This Page