Shockwave

Discussion in 'Plugin Development' started by WarmakerT, Oct 5, 2012.

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

    WarmakerT

    I'm making a plugin. It basically pushes everyone in a 5 blocks radius from the player away. How would I do this(I suck at thinking when it comes to vectors =\ )?
     
  2. Offline

    Woobie

    I was going to make something like this, but never knew how...
    Maybe getNearbyEntities and set their location 5 blocks away from yours? :D
    Maybe not...
     
  3. Offline

    kyle1320

    WarmakerT
    Code:
    Integer dist = 5;
    List<Entity> nearby = player.getNearbyEntities(dist, dist, dist);
    for (Entity e : nearby) {
        Location loc = player.getLocation();
        Location mloc = e.getLocation();
        Double distance = mloc.distance(loc);
        if (distance <= dist) {
            e.setVelocity((new Vector(mloc.getX() - loc.getX(), mloc.getY() - loc.getY(), mloc.getZ() - loc.getZ())).multiply(dist - distance).add(e.getVelocity()));
        }
    }
    You can change 'dist' to anything
     
    Woobie and WarmakerT like this.
  4. Offline

    Woobie

    Hah, knew it ;)
     
  5. Offline

    WarmakerT

    Could you please make it so they don't get pushed up? Only to the sides. Thanks in advance :)
     
  6. Offline

    kyle1320

    WarmakerT
    Sure, just use this line instead of the other:
    Code:
    e.setVelocity((new Vector(mloc.getX() - loc.getX(), 0, mloc.getZ() - loc.getZ())).multiply(dist - distance).add(e.getVelocity()));
     
  7. Offline

    WarmakerT

    Thanks :D
     
Thread Status:
Not open for further replies.

Share This Page