# Animated Particle Help please!

Discussion in 'Spigot Plugin Development' started by VivianMusic, Aug 13, 2018.

1. ### VivianMusic

Hey, I am trying to use this code:
Code (Text):
public void startCrateParticles(Location loc) {

Location spawnLoc = loc.clone().add(0.5, 0, 0.5);

double radius = 0.5;
for(double y = 0; y <= 3; y+=0.05) {
double x = radius * Math.cos(y);
double z = radius * Math.sin(y);
for(Player online : Bukkit.getOnlinePlayers()) {
if(online.getWorld().getName().equalsIgnoreCase("world")) {
online.spawnParticle(Particle.PORTAL, spawnLoc.getX() + x, spawnLoc.getY() + y, spawnLoc.getZ() + z, 0, 0, 0, 0, 1);
}
}
}
}
to achieve this type of particle effect (like on Hypixel) https://i.gyazo.com/37b5afe516dc9fcb96c4633428073120.mp4

but I'm just getting this

https://i.gyazo.com/fe7bb533c996f76ccfae91b483d7c5c9.mp4

How do I get it to animate and loop in circles around the chest?

Edit: another example - https://i.gyazo.com/27794800c8109d0ccde04a0a3db5489a.mp4

2. ### Michel_0

Wikipedia sais (in german): Where t is the amount of turns, h is the inclination / pitch (= distance between the turns), r is the radius and c is an offset (which you might not need).

So this results in:
Code (Java):
public List<Vector> getHelix(double increment, double radius, double pitch, double turns, double displacement, double offset) {
List<Vector> result = new ArrayList<>();
for (double t = 0.0d; t <= turns; t = t + increment) {
result.add(new Vector(radius * Math.cos(2 * Math.PI * (t - Math.toRadians(displacement))), radius * Math.sin(2 * Math.PI * (t - Math.toRadians(displacement))), pitch * t - offset);
}
return result;
}
You should call this method at least 2 times to generate 2 Helix forms with an phase displacement.
So it would look like:
Code (Java):
// 3 turns, by offset -1.5 and pitch 1.0 -> so middle will be at 0.0, increment as 0.05 as you suggested, no idea if this is good, just try it
List<Vector> zeroDeg = this.getHelix(0.05d, 0.5d, 1.0d, 3.0d, 0.0d, -1.5d); // 0° phase
List<Vector> hundreteightyDeg = this.getHelix(0.05d, 0.5d, 1.0d, 3.0d, 180.0d, -1.5d); // 180° phase
Then you got 2 helix lines, which will be on each side of the block (180° displacement), by making 3 circles and a height of overall 3 blocks.
Just try to animate them (synchronously by iterating over the lists) and see what comes out.

I didn't test the code.
I didn't check the code to be syntactically corrent.
I just wrote something out of my mind into the post window...
Good luck.

#2
Last edited: Aug 13, 2018
3. ### VivianMusic

Code (Text):
public void startCrateParticles(Location loc) {

List<Vector> zeroDeg = this.getHelix(0.05d, 0.5d, 1.0d, 3.0d, 0.0d, -1.5d); // 0° phase
List<Vector> hundreteightyDeg = this.getHelix(0.05d, 0.5d, 1.0d, 3.0d, 180.0d, -1.5d); // 180° phase

for(Player online : Bukkit.getOnlinePlayers()) {
if(online.getWorld().getName().equalsIgnoreCase("world")) {
online.spawnParticle(Particle.PORTAL, loc.getX(), loc.getY(), loc.getZ(), 0, 0, 0, 0, 1);
}
}

}
So this is what I got now.... this is all confusing

4. ### Michel_0

It shouldn't be to hard to make a location out of a vector. Why did you remove the first loop for iterating over the locations?
Code (Java):
public class AnimatePaths implements Runnable {
private List<List<Vector>> paths;
private Location reference;
private JavaPlugin main;
public AnimatePaths(JavaPlugin main, List<List<Vector>> paths, Location reference) {
this.main = main;
this.paths = paths;
this.reference = reference;
}
public void run() {
for (List<Vector> path : this.paths) {
for (Vector point : path) {
this.reference.getWorld().spawnParticle(Particle.PORTAL, this.reference.add(point.getX(), point.getY(), point.getZ(), 0, 0.0d, 0.0d, 0.0d, 0.0d);
this.reference.subtract(point.getX(), point.getY(), point.getZ();
}
}
}
}
There's nothing special in it... either you're lazy or you don't know Java...