Particle Effect Ring/Circle trouble Math needed

Discussion in 'Plugin Development' started by dbaum102, Jan 26, 2016.

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

    dbaum102

    Ok thank you for viewing my post I have looked everywhere and have not yet conquered the task. I am trying to make a ring of water drop particles where the player is looking and I have basic knowledge of Particle Effects and am using the Particle Effect class in a post somewhere on bukkit (very popular). I am just lacking the certain math concepts and how to use them. I know you use Sine and Cosine but I am unsure on how to develop a circle using particles. Any help is great thanks!
    Current Code:
    Code:
    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                        scheduler.scheduleSyncRepeatingTask(this, new Runnable() {                        
                            double t = 0;
                            public void run(){
                                  
                                t = t + 0.5;
                                Location loc = p.getLocation();
                                Vector direction = loc.getDirection().normalize();
                                double x = direction.getX() * t;
                                double y = direction.getY() * t + 1.5;
                                double z = direction.getZ() * t;
                                loc.add(x,y,z);
                                ParticleEffect.WATER_DROP.display(0, 0, 0, 10, 10, loc, 15);
                                for(Player ps : loc.getWorld().getPlayers()){
                                    if(ps.getLocation().distance(loc)<1.0){
                                               if(!ps.equals(p)){
                                                    ps.setHealth(20.0);
                                                       scheduler.cancelAllTasks();
                                              
                                                   }
                                               }                                  
                                           }
                                      
                                        loc.subtract(x,y,z);
                        
                    }
                 }, 0, 1);
    Basically what my code does right now is it creates the water drop particle in a line but instead of one particle appearing at that location I want to make the water drop appear in a circle like pattern which would appear to shoot a water ring and then heal the player it hits... I am lacking the knowledge on how to create a circle and am looking for any help.
     
    Last edited: Jan 26, 2016
  2. Offline

    mythbusterma

    @dbaum102

    Please never call scheduler.cancelAllTasks()...that's a very bad idea.

    Also, if you want to draw a circle, you figure out how many particles you want to draw, divide 2 * PI by that number, and iterate from zero to 2 * PI by the number you found. X will be the cosine of the loop index times the radius, and Y will be the sine.
     
    GamerzKing, Areoace and dbaum102 like this.
  3. Offline

    dbaum102

    Thanks trying that now I will post if I have any questions with that. Thanks again for your time.
    [EDIT] What should I use instead of scheduler.cancelAllTasks()

    @mythbusterma
    How would i determine that when the player performs the command that it shoots out the ring/circle where the player is looking. That is the idea I am going for I feel pretty dumb when it comes to sin/cos.

    EDIT call scheduler.cancelAllTasks() what would I use instead
     
    Last edited: Jan 26, 2016
  4. Offline

    mythbusterma

    @dbaum102

    Determine what, exactly? Two times PI? It's always 6.28 etc.
     
  5. Offline

    dbaum102

    Last edited: Jan 26, 2016
  6. Offline

    ChintziSecilMC

    MORGAN FREEMAN
     
  7. Offline

    dbaum102

  8. Offline

    mythbusterma

    @dbaum102

    Alright, what have you tried? And yea that's how you would get that.
     
  9. Offline

    dbaum102

    Trying to figure out what exact equation you mean by this, I tried this(didnt work the way I wanted):
    Code:
    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                        scheduler.scheduleSyncRepeatingTask(this, new Runnable() {                         
                            double t = 0;
                            double r = 2;
                            public void run(){
                                   
                                t = 0.5;
                                Location loc = p.getLocation();
                                Vector direction = loc.getDirection().normalize();
                                double x,y,z;
                                x = direction.getX() * t;
                                y = direction.getY() * t + 1.5;
                                z = direction.getZ() * t;
                               
                                for(double i = 0; i<500; i++){
                                    double total = (Math.PI*2)/50;
                                    x = direction.getX()+Math.cos(i)*t;
                                    y = direction.getY()+Math.sin(i)*t;
                                    z = direction.getZ()*t;
                                    loc.add(x,y,z);
                                    ParticleEffect.DRIP_WATER.display(0, 0, 0, 10, 10, loc, 15);
                               
                                }
                               
                                for(Player ps : loc.getWorld().getPlayers()){
                                    if(ps.getLocation().distance(loc)<1.0){
                                               if(!ps.equals(p)){
                                                    ps.setHealth(20.0);
                                                       scheduler.cancelAllTasks();
                                               
                                                   }
                                               }                                   
                                           }
                                       
                                        loc.subtract(x,y,z);
                            if (t > 30){
                                scheduler.cancelAllTasks();
                            }
                    }
                 }, 0, 1);
     
  10. Offline

    mythbusterma

    @dbaum102

    For the love of god, stop cancelling all tasks. You'll screw up all the other plugins on the server.

    You need to draw a circle, then move on to the next Y (or Z, in your case). This means you need nested loops.
     
  11. Offline

    dbaum102

  12. Offline

    mythbusterma

    @dbaum102

    Cancel the specific task ID, but you should use BukkitRunnables instead.
     
  13. Offline

    dbaum102

    Nvm i just changed it im dumb :p
    Code:
    this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
     
  14. Offline

    mythbusterma

  15. Offline

    dbaum102

    I got the ring to show up but its at the players feet and lags like crazy.
     
  16. Offline

    mythbusterma

    @dbaum102

    Well yea, you're doing a lot of stuff lol. Simplify your code, delete all that stuff, and start over. Read my post carefuly.
     
    dbaum102 likes this.
  17. Offline

    dbaum102

    @mythbusterma What would the z cordinate be?
    What i currently have is not working out. I read and am wondering what piece i am missing:
    Code:
    for(double i = 0; i<500; i+=Math.PI*2){
                                    x = direction.getX()+Math.cos(i)*.25;
                                    y = direction.getY()+Math.sin(i)*.25;
                                    z = direction.getZ()*t;
                                    loc.add(x,y,z);
                                    ParticleEffect.DRIP_WATER.display(0, 0, 0, 10, 10, loc, 15);                          
                                }
    [Edit] Any closer?
    Code:
    for(double i = 0; i<50/2*Math.PI; i+=Math.PI*2){
                                    x = Math.cos(i)*.25;
                                    y = Math.sin(i)*.25;
                                    z = direction.getZ()*t;
                                    loc.add(x,y,z);
                                    ParticleEffect.DRIP_WATER.display(0, 0, 0, 10, 10, loc, 15);                           
                                }
     
    Last edited: Jan 28, 2016
  18. Offline

    dbaum102

    Bump

    I have messed around a little and have a circle but it does not move in the direction player is looking as well as have it so the ring is tilted the way the player is looking. It currently is perpendicular to the ground around the player, cool but not what i am going for need help with vector i believe that is the issue with my code please take a look and help out thanks.

    Code:
    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                        id = scheduler.scheduleSyncRepeatingTask(this, new Runnable() {      
                            int dirX = 0,dirZ = 0;
                            double t = 0;
                            public void run(){
                                   
                                t += 1.5;
                                Location loc = p.getEyeLocation();
                                Vector direction = loc.getDirection().normalize();
                                double x = 0,y = 0,z = 0;
                               
                               
                                int amount = 360;
                                double increment = (2 * Math.PI) / amount;
                                for(int i = 0;i < amount; i+=5){
                                   
                                    dirX +=direction.getX();
                                    dirZ +=direction.getZ();
                                    double angle = i * increment;
                                    x = direction.getX() + (.5 * Math.cos(i));
                                    z = direction.getZ() + (.5 * Math.sin(i));
                                    y = direction.getY();
                                   
                                    loc.add(x,y,z);
                                    loc.setYaw((float) (Math.sin(i) * .5 * Math.cos(Math.PI/180 * loc.getYaw())));
                                    ParticleEffect.DRIP_WATER.display(0, 0, 0, 10, 10, loc, 15); 
                                    loc.subtract(x,y,z);
                                }   
                               
                               
                                for(Player ps : loc.getWorld().getPlayers()){
                                    if(ps.getLocation().distance(loc)<1.0){
                                               if(!ps.equals(p)){
                                                    ps.setHealth(20.0);
                                                       scheduler.cancelAllTasks();
                                               
                                                   }
                                               }                                   
                                           }
                                       
                                        loc.subtract(x,y,z);
                            if (t > 30){
                                scheduler.cancelTask(id);
                            }
                    }
                 }, 0, 1);
     
  19. Offline

    mcdorli

    Add a the player's direction to the center of the circle you have each time.
     
  20. Offline

    dbaum102

    which variable would I insert it into?
     
    Last edited: Feb 4, 2016
  21. Offline

    mcdorli

    @dbaum102 Inside the bukkitrunnanle, create a center vectot, amd every time the rinnable fores, add the player's direction to it, then use that vector, to positionvthe circle.

    Nope, not even close. _ is a valid java symbol, it's even used in some of the namijg types.
     
    dbaum102 likes this.
Thread Status:
Not open for further replies.

Share This Page