Hello! I'm experimenting with some particle shapes, circles, spheres, other shapes, and I found myself in a sticky situation. So what I want is this: I want to make a spiral using the direction vector from a player. Basically when a player hits the ground with for example a stick, particles spiral to about... well... I'm not exactly sure, it doesn't matter exactly how far it has to go. I have made a couple attempts to do this (all failed however, too badly) but I couldn't really find a good way. I've tried to do it using something like this, which did work in some way: (I forgot what exactly I did as I changed it later) PHP: $pos = $p->getPosition(); $direction = $p->getDirectionVector(); for($i = 0; $i <= 360; $i += 2) { $pos = $pos->add($direction); $x = (cos(deg2rad($i)) * 0.5) + $pos->x; $z = (sin(deg2rad($i)) * 0.5) + $pos->y; $p->getLevel()->addParticle(new FlameParticle(new Vector3($x, $pos->y + 1, $z))); } } This did did make the right shape (I think, as I could only see a curve), but it went out so far that I could only see a curve in the line of particles, which is because there is so much space between the particles thanks to the getDirectionVector(), which gives like a block space in between cause it uses the block the player is looking at. I know my code is not efficient and well... Not working, but it's pretty much a first timr for me and I don't know too much about this. I hope someone can help me with this, thanks in advance!
If you are referring to this shape (helix): where the axis is of any direction (including oblique) such that the helix also rotates along with the axis, I would make use of cross product. I would present my calculation mathematically (I calculated this a long time ago, and I forgot to define some variables, and now I already forgot what those variables represent, and right now I'm not in the mood to calculate it again): EDIT: This image is wrong. In the last equation, (x / |x|) sin(2nk[pi]) should be appended with a [cross] v. In code it would be like this: PHP: function helix(Vector3 $a, Vector3 $b, float $radius, float $cycles, callable $spawnParticle) { $density = 0.2; $x = $b->subtract($a); $length = $x->length(); $otherCross = new Vector3(1, 0, 0); if($otherCross->cross($x)->lengthSquared() == 0) // if parallel $otherCross = new Vector3(0, 1, 0); $v = $otherCross->cross($x)->normalize()->multiply($radius); $u = $v->cross($x->normalize()); for($i = 0; $i <= $x; $i += 0.1) { $k = $i / $length; $p = $a->add($x->multiply($k)) ->add($v->multiply(cos(2 * $cycles * $k * M_PI))) ->add($u->multiply(sin(2 * $cycles * $k * M_PI))); $spawnParticle($p); }} Again, if you found any mistakes, point them out. I wrote down my calculations a few months ago, and I have already forgotten what I was doing with u and v.
After thinking again, I think v is a vector of r long perpendicular to x, and u is a vector of r long perpendicular to both x and v. Hence x cross v would result in a vector perpendicular to both, with length |x| |v|, so I divide it with |x| to get back the length of r.