Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Circle

Comments in 'Plugin Development' started by Primus, Jul 19, 2015.

  1. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    I want to make a particle circle in sky so i need a function that will return only X n Z coordinates for next point on circle
    CraftYourBukkit likes this.
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    $center = new Vector3(111);
    $radius 0.5;
    $count 100;
    $particle = new WhateverParticle($center);
    for(
    $i 0$i $count$i++){
      
    $pitch = (mt_rand() / mt_getrandmax() - 0.5) * M_PI;
      
    $yaw mt_rand() / mt_getrandmax() * M_PI;
      
    $y = -sin($pitch);
      
    $delta cos($pitch);
      
    $x = -sin($yaw) * $delta;
      
    $z cos($yaw) * $delta;
      
    $v = new Vector3($x$y$z);
      
    $p $center->add($v->normalize()->multiply($radius));
      
    $particle->setComponents($p->x$p->y$p->z);
      
    $level->addParticle($particle);
    }
    AndrewBit, rvachvg, iJoshuaHD and 2 others like this.
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Thanks :)
  4. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
    Could you make the $center the coordinates of a player?
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    What player? I'm using it with Timer , you can go ahead use PlayerMoveEvent, but thats not pretty good idea
  6. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
    Why isn't it a good idea? It would look awesome!
    Legoboy0215 likes this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes. Simply replace $center with $player.
    BlackJIeB and PixelGuy75 like this.
  8. BlackJIeB
    Offline

    BlackJIeB New Member

    Joined:
    Oct 12, 2014
    Posts:
    28
    Minecraft User:
    BlackJIeB
    can you tell me how to make a spiral of particles?
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The following code makes one round per meter height, and makes up to two rounds (two meter high), spawning one particle per 1/20 meter:
    PHP:
    // $yaw is in radians
    for($yaw 0$y $center->y$y $center->2$yaw += (M_PI 2) / 20$y += 20){
      
    $x = -sin($yaw);
      
    $z cos($yaw);
      
    $particle->setComponents($x$y$z);
      
    $level->addParticle($particle);
    }
    jojoe77777, rvachvg and BlackJIeB like this.
  10. BlackJIeB
    Offline

    BlackJIeB New Member

    Joined:
    Oct 12, 2014
    Posts:
    28
    Minecraft User:
    BlackJIeB
    Oh my God you are the perfect person who does not speak in riddles, and immediately writes the code.
    Thank you! :3
  11. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    He isn't. He rarely does it like this... lol
    jojoe77777, RekkuzaRage, LDX and 2 others like this.
  12. BlackJIeB
    Offline

    BlackJIeB New Member

    Joined:
    Oct 12, 2014
    Posts:
    28
    Minecraft User:
    BlackJIeB
    However, however, a syntax error (in the for loop)
    PEMapModder likes this.
  13. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    lol
    jojoe77777 likes this.
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Right, the last semicolon should be replaced into a comma. My wrong.
    Because it's the first time I'm writing it, and I had time, and I found it interesting to write it :p

    Riddle example:
    Iterate from the starting height Y coordinate to the ending height. Regarding your desired spiral density, increase your yaw (in radians) by a little bit every time y increases. Using a similar algorithm to the center code above, use trigonometry to calculate the X and Z position of the particle. Adding the iterating Y, you get the XYZ to spawn the particle at.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I just got a new idea. What about making a plugin that plots a graph with particles? XD
    E.g. /particlegraph lavadrip "x^3 - x^2" -5 5 -5 5 0.1 0.1
    Plots a graph of y = x^3 - x^2 {-5 <= x <= 5, -5 <= x <= 5} in the scale 0.1 meter = 1 unit.
    Last edited: Jul 21, 2015
    LDX, Xenturio and BlackJIeB like this.
  16. BlackJIeB
    Offline

    BlackJIeB New Member

    Joined:
    Oct 12, 2014
    Posts:
    28
    Minecraft User:
    BlackJIeB
    Still not working :D
    Anyway the previous code in a complete circle cool :)
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    How does it not work?
    BlackJIeB likes this.
  18. BlackJIeB
    Offline

    BlackJIeB New Member

    Joined:
    Oct 12, 2014
    Posts:
    28
    Minecraft User:
    BlackJIeB
    My code: (your code :D)
    Code:
        public function spiral(PlayerMoveEvent $event) {
            $player = $event->getPlayer();
            if ($player instanceof Player) {
                if ($player->getInventory()->getItemInHand()->getId() == 351) {
                    $sender = $event->getPlayer();
                    $level = $sender->getLevel();
                    $x = $player->getX();
                    $y = $player->getY();
                    $z = $player->getZ();
                    $center = new Vector3($x, $y, $z);
                    $radius = 0.5;
                    $count = 100;
                    $particle = new HeartParticle($center);
                    for ($yaw = 0, $y = $center->y; $y < $center->y + 2; $yaw += (M_PI * 2) / 20, $y += 1 / 20) {
                        $x = -sin($yaw);
                        $z = cos($yaw);
                        $particle->setComponents($x, $y, $z);
                        $level->addParticle($particle);
                    }
                }
            }
        }
    nothing happens when holding item id 351
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    (Irrelevant) Why $sender? Just keep using $player.
    BlackJIeB likes this.
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Oops, it should be like this:
    PHP:
    // $yaw is in radians
    for($yaw 0$y $center->y$y $center->2$yaw += (M_PI 2) / 20$y += 20){
      
    $x = -sin($yaw) + $center->x;
      
    $z cos($yaw) + $center->z;
      
    $particle->setComponents($x$y$z);
      
    $level->addParticle($particle);
    }
    BlackJIeB likes this.

Share This Page

Advertisement