# Tutorial Creating a helix / 3d spiral out of particles

Discussion in 'Resources' started by Skionz, Sep 28, 2014.

Not open for further replies.
1. Offline

#31
2. Offline

### ChipDev

Pretty long post, but lets show this off.
Using ParticleEffect lib by DarkBladee12 , You are able to spawn particles but not in a helix (Because some may not want any Y change) - But that would not let the cosine/sin change due to the Y not changing.

The solution is having a double as *Hight* and putting a runnable that does it every x ticks.
(The runnable and on-enable is totally just an example!)
Code:java
`public void onEnable() {Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {@Overridepublic void run() {for(Double y = player.getEyeLocation().getY();// ^ start of loop is at the eye location.y < player.getEyeLocation().getY() + 6.0;//^ Y loops up 6 blocks above (We will subtract later)y+= 0.06) {//^ Up Y by 0.06 for a good amount of particles. Do some math and this is 100 particles. (6 / 0.06)}}},(long) 0, (long)2);}`

Now that we have that double, we will get some basic cosine (X) and sin (Z) features.
Code:java
`public void onEnable() {Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {@Overridepublic void run() {for(Double y = player.getEyeLocation().getY();y < player.getEyeLocation().getY() + 6.0;y+= 0.06) {Double xcos = Math.cos(y) * 0.8;// ^ Getting the X coordinate (well, adding it)Double zcos = Math.sin(y) * 0.8;// ^ Z coord}}},(long) 0, (long)2);}`

Then...
Code:java
`public void onEnable() {Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {@Overridepublic void run() {for(Double y = player.getEyeLocation().getY();y < player.getEyeLocation().getY() + 6.0;y+= 0.06) {Double xcos = Math.cos(y) * 0.6;Double zcos = Math.sin(y) * 0.6;this.newloc = new Location(player.getWorld(), player.getLocation().getX() + xcos, y - diff + 0.7, player.getLocation().getZ() + zcos);//We added a static variable at the start of the code//So now we can store and edit the variable from other//classes!//NOTE: why + 0.7? Its just adding a little Y to the location,// so it Isn't blocking the player's eyes.ParticleEffect.FIREWORKS_SPARK.display((float) 0.0, (float)0.0, (float)0.0, (float)0.0, 1, newloc, 16);//Spawns particle effects}}},(long) 0, (long)2);}`

That adds cos + X and sin + Z and subtracts Y to its regular amount, Yes java, you just got loopholed!
And theres it. we have this really nice hula effect you can probably sell for \$5, and it looks awesome. Heres what it looks like!:

And then, you can change some raidus stuff Z = * 0.4 and X = * 0.8 (With flame) and it will look like a oval!

Dat style! And then... *Drumrole... - And all the possibilities with randoms..

These are some ideas for particles; the ideas are endless!
Thanks for reading. and always thank Skionz!

#32
3. Offline

### BurnerDiamond

@Skionz

is it possibile to check if an arrow, hits your helix?

If so with a couple a randoms and a couple of teams, a grat mini game is born!

//////////////////////////////

Even better can you imagine a space invaders game with these helix's pulling you up to the sky?

Last edited: Mar 1, 2015
#33
4. Offline

### Skionz

You would have to store each particle's location and constantly check the arrow's location so it would probably be bad idea.

#34
5. Offline

### BurnerDiamond

Damn, oh well maybe particles are just made to look nice!

#35
Skionz likes this.
6. Offline

### Finn_Bueno_

Could you tell me how to make it into a tornado ?

#36
7. Offline

#37
8. Offline

### Finn_Bueno_

The way you did it, didn't work for me =/
I did what @ChipDev did, but I would like to know how to make a tornado using That code.
(Nothing against the way you did it, it just didn't work )

#38
ChipDev likes this.
9. Offline

### Msrules123

EDIT: Nevermind. Wrong information on my part.

Last edited: Mar 25, 2015
#39
10. Offline

### Concar123

um im a derp and i need help doing this....... im using IntelliJ and half of the things you guys put in your code, dont work for me....

#40
11. Offline

### ChipDev

Show me some errors or a screenshot please.. Did you import the ParticleEffect LIB?

#41
12. Offline

### teej107

@ChipDev Hey, you're back!

@Concar123 We can't help you without a more detailed description of why it doesn't work.

#42
13. Offline

### ChipDev

Hey, I am back Thanks!

#43
14. Offline

### Concar123

im sorry xD when im on ubuntu my internet jacks up hang on xD ill post a screenshot as soon as i can fricking get my ubuntu to stop being a bunghole xD

#44
15. Offline

### PoseidonGraphics

Code:
`            PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles("fireworksSpark", (float) (loc.getX() + x), (float) (loc.getY() + y), (float) (loc.getZ() + z), 0, 0, 0, 0, 1);`
Error: http://prntscr.com/6t2zcj

16. Offline

### Skionz

That constructor does not exist. Use the correct one corresponding to the version of CraftBukkit you are using.

#46
17. Offline

### plisov

Does this still work? When I try to code this, the new PacketPlayOutWorldParticles("fireworksSpark", (float) (loc.getX() + x), (float) (loc.getY() + y), (float) (loc.getZ() + z), 0, 0, 0, 0, 1); becomes red and asks me to remove everything BUT new PacketPlayOutWorldParticles(). I have ProtocolLib in my build path. Please help

#47
18. Offline

### Skionz

ProtocolLib is not required. Use the correct constructor corresponding to the version of CraftBukkit you are using.

#48
19. Offline

### Concar123

Um... I figured out my problem but can anyone show me code for like an item that would activate it? like a gadget xD and also to make the firework spark a different color... how would i do that? im sort of new to bukkit xD

#49
20. Offline

### ChipDev

Why overuse xD?These basics should be learned before trying that.

#50
21. Offline

### Jimfutsu

Hey, just a quick question, how would you go about compacting the helix?

#51
22. Offline

### nverdier

Last edited by a moderator: Jun 26, 2015
#52
23. Offline

### MCTV

guys how would i make the helix shoot in a direction? im having trouble using the direction vector ;( and where to put it

#53
24. Offline

### Misteroid

@Skionz will this work with 1.8.7

#54
25. Offline

### Skionz

Yes, assuming you use the new PacketPlayOutWorldParticles constructor.

#55
26. Offline

### Misteroid

Do u know how to use it? I dont :/

#56
27. Offline

### Skionz

Create an instance of it, and invoke PlayerConnection#sendPacket(Packet).

#57
28. Offline

### xXCapzXx

^^
I need this...

This code makes 1 swirl around my body, but how do I make it like @ChipDev tornado?
Code:
```package me.capz.helix;

import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

import de.slikey.effectlib.EffectLib;
import de.slikey.effectlib.EffectManager;
import de.slikey.effectlib.effect.AnimatedBallEffect;
import de.slikey.effectlib.util.ParticleEffect;

public class version2 extends JavaPlugin {

EffectManager em;

public void onEnable() {

EffectLib lib = EffectLib.instance();
em = new EffectManager(lib);
}

public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
if(cmd.getLabel().equalsIgnoreCase("flamey")) {
Player player= (Player)sender;
flamey(player);

}
return true;
}

private void flamey(Player player) {
Location l = player.getLocation();
Vector vector = new Vector();
double maxHeight = 10;
for(int i1 = 0; i1 < 1; i1++) {
for(Double y = player.getEyeLocation().getY(); y >= 20; y += 0.06) {
double x = 2 *  Math.cos(y) * 0.8; // Basically it is saying 3 * Math.cosine and sine, to make a helix around eachother.
double z = 2 * Math.sin(y) * 0.4;

net.minecraft.server.v1_7_R3.PacketPlayOutWorldParticles packet = new net.minecraft.server.v1_7_R3.PacketPlayOutWorldParticles("flame",
((float) (l.getX() + x)),
((float) (l.getY() + y)),
((float) (l.getZ() + z)),
0, 0, 0, 0, 1);

((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}
}

}

```
I want it to be more compact so it can be a tornado

EDIT by Moderator: merged posts, please use the edit button instead of double posting.

Last edited by a moderator: Jun 14, 2016
#58
29. Offline

### ChipDev

Can you send me a video or .gif of the effects?

#59
30. Offline

### xXCapzXx

This is the proper code:
Code:
```package me.capz.helix;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

import de.slikey.effectlib.EffectLib;
import de.slikey.effectlib.EffectManager;
import de.slikey.effectlib.effect.AnimatedBallEffect;
import de.slikey.effectlib.util.ParticleEffect;

public class version2 extends JavaPlugin implements Listener{

public void onEnable() {

}

public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
if(cmd.getLabel().equalsIgnoreCase("flamey")) {
Player player= (Player)sender;
flamey(player);

}
return true;
}

private void flamey(Player player) {
Location l = player.getLocation();
for(int i1 = 0; i1 < 20; i1++) {
for(double y = 0; y < 20; y+= 0.05) {
double x =  Math.cos(y * radius);
double z =  Math.sin(y * radius);

net.minecraft.server.v1_7_R3.PacketPlayOutWorldParticles packet = new net.minecraft.server.v1_7_R3.PacketPlayOutWorldParticles("flame",
((float) (l.getX() + x)),
((float) (l.getY() + y)),
((float) (l.getZ() + z)),
0, 0, 0, 1, 0);

((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}

}

}

```
When you do /flamey it will create a helix that goes 20 blocks high, but I want it to be more compact and more like a tornado.

It is the code from this video:

#60