Tutorial 1.8 Particle Lesson #1 Helix / Spiral

Discussion in 'Resources' started by Herowise, Feb 19, 2016.

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

    Herowise

    Particle Lesson #1 (Helix)

    WARNING:
    This particle movement code is a little too advanced or intermediate, I recommend you learning plugin basics first or if you can handle through it, you can surely have a go!

    The Start of a new journey!

    So this is my first particle movement, tutorial, using maths to make cool effects!
    This is a basic helix created by sin and cos to make this effect. So there will be more of these tutorials so stay tuned ^-^ !!!

    [​IMG]
    As we can see the parametric equation is already there and we just need to manipulate it to suit our needs.

    1) We create a new method:
    Code:
    public class SpiralHelix extends JavaPlugin {
    
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
                if(cmd.getName().equalsIgnoreCase("particle")){
                    Player player= (Player) sender;
                             createHelix(player);
                }
    Explanation:
    So the class is called "SpiralHelix" but you can rename it to your favorable class name. We extended JavaPlugin to show Java and Bukkit that we are making a Java Plugin. the next Public Boolean.... and onward is the basic command sender such as "/kill <args>", after that we are creating a command called "particle" so whenever we give this command, we are gonna execute the plugin movement which we are gonna do next! The Player player = (Player) sender;" is there because it is checking the player who sends it!
    The "createHelix(player);" will be used for later purposes.
    There are many ways to trigger the particle method such as right clicking air or certain blocks, and there are tons of them. But as this being basic I'll go through this.



    2) We create a method which will get the player's coordinates:
    Code:
    public void createHelix(Player player) {
                Location loc = player.getLocation();
    Explanation:
    So here we are getting the player Coordinates for spawning the particle and this will be the method where we are gonna span in the particles and send the players as packets.

    3) We create the equation!
    Code:
     int radius = 2;
                for(double y = 0; y <= 50; y+=0.05) {
                    double x = radius * Math.cos(y);
                    double z = radius * Math.sin(y);
    Explanation:
    So this is the typical part... If you weren't smart or weren't bothered listening in the maths class this is gonna be your worst nightmare. As we can see maths can create awesome particle movements and Minecraft can execute it on the 3D plane! This will later get added in the "createHelix()" method.

    4) We send the players the packets!
    Code:
     PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(EnumParticle.BARRIER,true, (float) (loc.getX() + x), (float) (loc.getY() + y), (float) (loc.getZ() + z), 0, 0, 0, 0, 1);
                    for(Player online : Bukkit.getOnlinePlayers()) {
                        ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
                    }
    Explanation:
    So this is the packet sending code which will send the packets to all online players and also the part where you say, "EnumParticle.BARRIER" you can change the particle type. This code can be change just replacing "BARRIERS" with something else like "FLAME".

    5) The Finale!
    Code:
    public class Core extends JavaPlugin {
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
                if(cmd.getName().equalsIgnoreCase("herowise")){
                    Player player= (Player) sender;
             
                    createHelix(player);
                }
         
            return false;}
     
            public void createHelix(Player player) {
                Location loc = player.getLocation();
                int radius = 2;
                for(double y = 0; y <= 50; y+=0.05) {
                    double x = radius * Math.cos(y);
                    double z = radius * Math.sin(y);
                    PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(EnumParticle.BARRIER,true, (float) (loc.getX() + x), (float) (loc.getY() + y), (float) (loc.getZ() + z), 0, 0, 0, 0, 1);
                    for(Player online : Bukkit.getOnlinePlayers()) {
                        ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
                    } 
                }}
    Explanation:
    Nothing to explain here but this the class where we accumulated and summed up all the code we did earlier.

    If you find any errors you surely can tell me to fix them or make it easier to explain them.

    If you enjoyed this or learnt something you surely can comment ^-^ and it will b e appreciated and I'm glad if i taught you something new!

    [​IMG]
    This is one of the maths and the reason behind the helix using 3D plane!



    Minecraft Screenshots:

    Helix : Barrier_Blocks:
    [​IMG]


    Helix : Flame (Radius is shortened to look a more aesthetic way):
    [​IMG]




    Nest Lesson (Comment on which one you wanna see in the future!):

    2016-02-09_19.45.40.png

    Blood Helix by Steezyy or from Mineplex!

    or


    Butterfly Curve (SURPRISE)!
     
  2. Nice tutorial! But the light blue font is hard to read on the white background. pls change

    Ps: How about sphere, rectangle, triangle in the next lessons?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Feb 19, 2016
    Herowise likes this.
  3. Offline

    ChipDev

    Looks cool - I could give some ideas if you want to add some on to that. After all, @Skionz made a tutorial on this a long time ago, and this adds on to it! One thing: How did you get the barriers so small? Is it just perspective, or are you actually standing INSIDE of the location?
     
  4. Offline

    Herowise

    xD I spawned it on my location and its the perspective! As I moved.


    @FisheyLP , Sure I'll make my next tutorial on Spheres! ;)
     
  5. Offline

    ChipDev

    Im working on spheres myself- And it's not going so good!

    @Herowise
    Im rendering easy 2d circles (No height) to the point where it becomes a 3D sphere. Just, I cannot get the radius right and its kinda arcing upwards at the end- but RIGHT NOW I'm working one t!
     
  6. Offline

    Herowise

    Send me the code I will try fixing it!
     
  7. Offline

    ChipDev

    Thanks. Let me explain:
    Code:
    public void circleAround(Player player) {
            double maxHeight = 2;
            int sphereCircles = 30;
            double height = 0;
            for(double r = 0; r <= Math.PI; r+=Math.PI / sphereCircles) {
                for(double t2 = 0; t2 <= 2*Math.PI; t2+=2*Math.PI / 30) {
                   double x = Math.sin(t2) * sin(r);
                   double y = height;
                   double z = Math.cos(t2) * sin(r);
                   ParticleEffect.VILLAGER_HAPPY.display(0, 0, 0, 0, 1, new Location(player.getWorld(),
                   x + player.getLocation().getX(),
                   y + player.getLocation().getY(),
                   z + player.getLocation().getZ()), 32);
                }
                height+=(maxHeight/sphereCircles);
            }
        }
    the Loop "r" is practically the rendering of 3D circle, which is made of 2d circles, which the sphereCircles will make 30 of bottom-to-top. This loop will also count the radius, (Which is the problem in this case. It renders as sine, (which curves up at the top), and I want it to be a half-circle. Then, t2 just renders the 2d circle itself.
    TLDR; Test it xD
     
  8. Offline

    Herowise

    Did you want to create something like this. 2016-02-21_10.46.58.png
     
  9. Offline

    ChipDev

    Nope! I wanted a sphere around my player, I am good at making helices tho!
     
  10. Offline

    mcdorli

    There's a way, to make spheres with almost no effort at all. Create a vector with 3 random sizes in each direction between -1 and 1, normalize it, then multiply it by ypur radius.
    It sadly makes them a bit random, but better than nothing, and only requires 3 (possibly 2) lines of code for each particle.
     
  11. Offline

    SteeZyyy

    Blood Helix by Steezyy or from Mineplex!
    Someone showed this post to me and I think it's really awesome when people reference my work. I think you could doo a great job explaining the coding side which my lesson lacked as my videos focus more on the math side of the particle effects.
    -SteeZyyy
     
    GamerzKing and Herowise like this.
  12. Offline

    Herowise

    xD I really like your work and, Yes! I am working at the Blood helix Post atm!
     
  13. Offline

    SteeZyyy

    Thanks! Look forward to checking out more of your lessons. If you have a question specifically about math I used I can try to answer it but I'm sure you're more than capable yourself :)

    This should be helpful I hope :^)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Mar 3, 2016
    hsndmrts98 likes this.
  14. Offline

    uyscutix

    Can someone explain to me why i'm getting errors?

    I got errors from this line (coming from the word "EnumParticle"):

    Code:
    PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(EnumParticle.BARRIER,true, (float) (loc.getX() + x), (float) (loc.getY() + y), (float) (loc.getZ() + z), 0, 0, 0, 0, 1);
    Note: I have the ParticleEffect class (if that's needed) yet I still got an error.
     
  15. Offline

    pretocki3

    @uyscutix What version you are using? Older version hasn't EnumParticle class.
    And you don't need ParticleEffect class to use particle. You can use raw packet.
     
Thread Status:
Not open for further replies.

Share This Page