Solved Creating a circle out of particles

Discussion in 'Plugin Development' started by MrJossy, Apr 26, 2015.

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

    MrJossy

    Hello! So... I am trying to create a circle out of particles. If anyone could help me, that would be very nice!

    Thanks for reading and have a nice day!
     
  2. Offline

    Rocoty

    What have you tried?
     
  3. Offline

    mythbusterma

    @MrJossy

    Depends how you want this circle to look, and what you're doing with it. Although I will give you a hint, trigonometry is very useful for this.
     
  4. Offline

    MrJossy

    I would just create a 3D circle out of paticles. I tried to look for cos and sin formulas but I can't get the correct one. @mythbusterma
     
  5. Offline

    sgavster

  6. Offline

    mythbusterma

    @MrJossy

    Since I realise that the math is not obvious to some, here's the math for you.

    Code:
    int scaleX = 1;  // use these to tune the size of your circle
    int scaleY = 1;
    double density = 0.1;  // smaller numbers make the particles denser
    
    for (double i=0; i < 2 * Math.PI ; i +=density) {
         double x = Math.cos(i) * scaleX;
         double y = Math.sin(i) * scaleY;
    
         // spawn your particle here
    }
     
    ChipDev and MrJossy like this.
  7. Offline

    MrJossy

    Thank you very much! I will try this when I get home!
     
    ChipDev likes this.
  8. Offline

    sgavster

    @mythbusterma @MrJossy I tried it, it works great. Just remember: the x is the actual x, but the double y should be z, and you should add it to player.getLocation().getZ or .getX.
     
  9. Offline

    mythbusterma

    @sgavster

    Depends on what orientation you want the circle in. I was assuming X-Y.
     
  10. Offline

    sgavster

    @mythbusterma Yeah, I didn't think of that.. Lol, I'm not very smart today, it's vacation; thinking isn't my thing :p
     
  11. Offline

    MrJossy

    Well... I tried and it does not seem to work. It creates a line. @mythbusterma

    Code:
    int scaleX = 2;
    int scaleY = 2;
    double density = 0.1;
    for(double i = 0; i < 2 * Math.PI; i+=density){
       double x = Math.cos(i) * scaleX;
       double y = Math.cos(i) * scaleY;
                             
        PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles("flame", (float) (loc.getX() + x), (float) (loc.getY()), (float) (loc.getZ() + z), 0, 0, 0, 0, 1);
    
       for (Player online : Bukkit.getOnlinePlayers()){ 
           ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
       }
     
  12. Offline

    mythbusterma

    @MrJossy

    ......how about you look at your code and actually read it.
     
  13. Offline

    MrJossy

    I know that there is a Loc.getZ() + z but that was me! I got wrong copying the code from eclipse to here. In my code, it's Loc.getZ() + y
     
  14. Offline

    mythbusterma

    @MrJossy

    Then why are you using the cosine function for both X and Y? One has to be sine, the other cosine.
     
  15. Offline

    MrJossy

    Oh. Lol. I will fix that and see if it works. But the particles. Are they getX() + x and getZ() + y ?? @mythbusterma

    EDIT: I fixed it. Thanks a lot to @mythbusterma
     
    Last edited: Apr 29, 2015
Thread Status:
Not open for further replies.

Share This Page