Lassoing a player

Discussion in 'Plugin Development' started by NeerDev, Jul 10, 2015.

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

    NeerDev

    I'm trying to make it so when a player right clicks another player entity while holding a leash the player who was clicked will be launched into the air in the direction of the clicker (effectively a lasso). I'm trying to get the direction of the vector that the player will be launched but I keep running into issues. Shouldn't it be possible to just launch the player in the negative (opposite) vector of the player who clicked (I would need to also add a y vector).
    Any ideas on how I could implement this?
     
  2. Offline

    mythbusterma

    @NeerDev

    If you take the Locations of the both the players as Vectors and subtract them, then normalise it, you'll have a vector that points from one player to the other. You can multiply this by a constant (e.g. 5) to set the velocity that the "lassoed" player will be launched with, and then apply this Vector to the Player as their velocity.
     
    NeerDev likes this.
  3. Offline

    NeerDev

    @mythbusterma

    Awesome, works perfectly. Thanks.

    For those who are interested:


    Code:
    if( damagerentity instanceof Egg )
            {
                Player damagedentity = (Player) event.getEntity();
                Egg egg = (Egg)damagerentity;
                Player shooter = (Player) egg.getShooter();
                shooter.sendMessage(ChatColor.DARK_GREEN + "Your lasso launches the player towards you!");
               
                Vector ldamaged = damagedentity.getLocation().toVector();
                Vector lshooter = shooter.getLocation().toVector();
                Vector lasso = ldamaged.subtract(lshooter).normalize().multiply(-10);
               
                damagedentity.setVelocity(lasso);
               
            }
    Note I used the egg for simplicity sake, works better over long distance and is barely visible at speed.
     
Thread Status:
Not open for further replies.

Share This Page