# Solved Helix issue

Discussion in 'Plugin Development' started by Saday, Jun 28, 2018.

Not open for further replies.
1. Offline

I have been attempting to create a helix that takes into account the players's yaw and pitch in order to spawn it where the player is facing. However it just makes a straight line and I am not sure why (not where the player is facing). I have been searching everywhere for the solution and have not been successful.

Current code: https://pastebin.com/Sfd0T6D5

#1
2. Offline

### PhantomUnicorns

The first thing I would think of is that x, y, z might be equal to zero. Though this contradicts what I would think by looking at the code, could you attempt a debug message that prints those numbers? If it prints something other then zero, could you print the location's x (location.getX()) to confirm that the location's x is correct.

3. Offline

Last edited: Jun 29, 2018
#3
4. Offline

### MightyOne

Right away I can say: bravo, you are working on a tough topic. This kind of geometry isn't that easy anymore.
Further I can say idk what exaclty you friend tried to code but I think it a wrong approach xD sorry

My concept (which worked for me) was to first create a the current part of the helix as a vector facing yaw: 0 pitch: 0 and afterwards rotate it around the player's yaw and pitch. The code I used looked like this:

Firstly, there was a mistake about the yaw calculation. I used these values:
Code:
```double yaw    =  Math.toRadians(loc.getYaw() + 90);
So the vector for a default helix without rotation would look like this:
Code:
```angle += 181

Vector vec = new Vector(
angle / 1800D,
it would just be a helix along the x-axis.

To get it facing into the direction the player was looking I used this piece of code:
Code:
```double x, y, z;

//pitch rotation
x = vec.getX();
y = vec.getY();
vec.setX(x * Math.cos(pitch) - y * Math.sin(pitch));
vec.setY(x * Math.sin(pitch) + y * Math.cos(pitch));

//yaw rotation
x = vec.getX();
z = vec.getZ();
vec.setX(x * Math.cos(yaw) - z * Math.sin(yaw));
vec.setZ(x * Math.sin(yaw) + z * Math.cos(yaw));```
You don't really have to understand it...

Last thing would be to apply the vector to a copy of the location and spawn the particle there:
Code:
```world.spawnParticle(particle, loc.clone().add(vec), 1);
```
Furthermore I think you spawnHelix() methode dosn't need to be static at all, and I think you should rather run your BukkitRunnable as a timer than running it asynchronously and using Thread.sleep()

#4
5. Offline

You calculate your x twice? Is that not pointless...?

First of all, thank you. I will try to use this to make it work. Second, I originally made it non static and with a runnable, a friend helped and that is how it ended up.

Edit: THANK YOU SO MUCH IT WORKS

Last edited: Jun 30, 2018
#5
MightyOne likes this.
6. Offline

### MightyOne

Woooh once in a thousand years this knowledge is useful! XD

#6