Send all players X Block from each other.

Discussion in 'Plugin Development' started by Moon_werewolf, Apr 23, 2013.

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


    I need to know how many block I need to send each player for them to be X amount of block from each other. So far I have (all start from 0, 0)

    double degree = 360.0 / (double)players.size();
            double rad = Math.toRadians(degree);
    Then I know how many degrees the are between each player. But how far do i need to send them?
  2. Offline


    Do you want to calculate it in 2D space or 3D space?
    If you only care about 2D then use Pythagoras
    If you want to get the distance in 3D then apply Pythagoras twice.
    Oh and make sure to use the delta between the two players not their actual coordinates.
  3. Offline


    Thanks, and I only care about 2D. So pythagoras it is.
    Its not only two players. It can be any number of players
  4. Offline


    You could get a list of players, then teleport one, get his location, add however many blocks to it, then teleport 1-4 more players since you have 4 directions. Then you can keep doing this for the rest of the players.
    CarPet likes this.
  5. Offline


    Round about way and would still get the job done. Great Job!
  6. Offline


    If you want all players to be equally far from each other it's close to impossible when you have 5 or more players and only three dimensions.
  7. Offline


    No, it'll probably only be impossible with 1 player or no players. It'll just involve thinking. Math, everyone!

    Something like this:

    double xOffs = center.getX() + (distance*Math.cos(Math.toRadians(angle))); //Distance may have to be reduced
    double zOffs = center.getZ() + (distance*Math.sin(Math.toRadians(angle))); //Distance may have to be reduced
    center is the Location that represents the center of the circle.

    Then apply it to a vector. Velocity is applied every tick, so you'll have to be careful there.
  8. Offline


    I know of no geometrical object with more then 4 edges where every edge is equally far from each other.
    2 players is a line
    3 players is a triangle
    4 players is a tetrahedron
    5 ?

    Spreading them out in a circle where all players are equally far from the center is easy and possibly the best way to do it.

    You could just do this:
    int radius = 100; // Players will be 100 blocks from center
    double radians = (2 * Math.PI) / Bukkit.getOnlinePlayers().length;
    int i = 0;
    for(Player player : Bukkit.getOnlinePlayers()) {
      double x = radius * Math.Cos(radians * i) + center_x;
      double z = radius * Math.Sin(radians * i) + center_z;
      double y = world.getHighestBlockYAt(x, z);
      player.teleport(x, y, z);
  9. Offline


    Since the y-value doesn't really matter, you can just use 2D shapes.
    5- Pentagon
    6- Hexagon
    8- Octagon
  10. Offline


    What i meant when i said all edges are equally far from each other is that all edges are equally far from each other. In a pentagon, edge 2 and 4 for example are not equally close to each other as 3 and 4. :)
  11. Offline


    I guess that's true.

    Like LucasEmanuel said, it's probably only possible by sending players out from the center.
    Location center; //Your location
    double distance; //Distance you want to send the players
    Player[] players; //The players you have
    double angle = Math.toRadians(360/players.length); //Angle for each player, in radians
    for(int i = 0; i < players.length; i ++) //Loop through the players
        Player p = players[i];
        double x = center.getX() + (distance*Math.cos(angle*i)); //x
        double z = center.getZ() + (distance*Math.sin(angle*i)); //z
        double y = p.getWorld().getHighestBlockAt(x, z);
        //This teleports players, but you could try something else
        p.teleport(new Location(p.getWorld(), x, y, z));
Thread Status:
Not open for further replies.

Share This Page