Issue trying to get locations to play effects in cone shape

Discussion in 'Plugin Development' started by ferrago, Jun 27, 2014.

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

    ferrago

    Hey I can't figure out why this chunk of code isn't working.

    First is the Circle Creation method

    Code:java
    1. private static ArrayList<Location> circleBuilder (Location loc, Integer r, Integer h, Boolean hollow, Boolean sphere, int plus_y) {
    2. ArrayList<Location> circleblocks = new ArrayList();
    3. int cx = loc.getBlockX();
    4. int cy = loc.getBlockY();
    5. int cz = loc.getBlockZ();
    6. for (int x = cx - r; x <= cx +r; x++)
    7. for (int z = cz - r; z <= cz +r; z++)
    8. for (int y = (sphere ? cy - r : cy); y < (sphere ? cy + r : cy + h); y++) {
    9. double dist = (cx - x) * (cx - x) + (cz - z) * (cz - z) + (sphere ? (cy - y) * (cy - y) : 0);
    10. if (dist < r*r && !(hollow && dist < (r-1)*(r-1))) {
    11. Location l = new Location(loc.getWorld(), x, y + plus_y, z);
    12. circleblocks.add(l);
    13. }
    14. }
    15.  
    16. return circleblocks;
    17. }


    That one works correctly and playing effects at each location works out rather well. Now when I try using that to get a circle and then only play effects at a certain amount of the locations in a cone like area doesn't work. Here is that code.The circle method basically just calls circle builder with sphere being false and passes the rest normally.

    Code:java
    1. public static ArrayList<Location> getSemiCirlce(Player player, int radius, double arc, int height) {
    2. ArrayList<Location> targets = new ArrayList();
    3. if (arc <= 0) return targets;
    4.  
    5. // Initialize values
    6. Vector dir = player.getLocation().getDirection();
    7. dir.setY(0);
    8. double cos = Math.cos(arc * Math.PI / 180);
    9. double cosSq = cos * cos;
    10. double dirSq = dir.lengthSquared();
    11. ArrayList<Location> list = circle(player.getLocation(), radius, height, true, 1);
    12. // Get the targets in the cone
    13. for (Location loc : list) {
    14.  
    15. // Greater than 360 degrees is all targets
    16. if (arc >= 360) {
    17. targets.add(loc);
    18. }
    19. // Otherwise, select targets based on dot product
    20. else {
    21. Vector relative = loc.subtract(player.getLocation()).toVector();
    22. relative.setY(0);
    23. double dot = relative.dot(dir);
    24. double value = dot * dot / (dirSq * relative.lengthSquared());
    25. if (arc < 180 && dot > 0 && value >= cosSq) {
    26. targets.add(loc);
    27. }
    28. else if (arc >= 180 && (dot > 0 || dot <= cosSq)) {
    29. targets.add(loc);
    30. }
    31. }
    32.  
    33. }


    xTigerRebornx fireblast709 either of you have an idea about this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    xTigerRebornx

    ferrago Shouldn't randomly tag people.
    What do you expect to happen and what actually happens? Debug your code, print out all your values and see what may not be what you expect outputted.
     
  3. Offline

    ferrago

    xTigerRebornx Just trying to get a helping hand, didn't mean to upset anyone, y'all both seemed up for a challenge.
    But I have debugged it very thoroughly, I am playing a particle effect at the location. The cirlce() method used alone plays a circle of the particles around the center location. That fully works. I then push that circle() method through this semicircle() method, I have tested make sure points are getting added, the size of the array is oddly in 400 range, but even still the effects aren't playing anywhere that I can see. I know my particle method isn't to blame since I use it all over the place and have never had the slightest problem.
     
  4. Offline

    xTigerRebornx

    ferrago See if you are actually playing the particles server-side, and print out the locations in the List, see if their values match up to what is expected.
     
  5. Offline

    ferrago

    #facepalm. Was an issue with pointers and whatnot. Twas performing calculations on a location then storing that location not a clone, which was making things go whack.
     
Thread Status:
Not open for further replies.

Share This Page