I wanted to know how can i set the the projectile vector for this three skulls, I want them to still be launched from the player head, but in different directions.Two would go to the sides and one would go as it does now. What i tried to do was setting a vector "Vector vector = new Vector(5, 0, 0);" and then using it in setVelocity() although that didnt work.Sorry I am a noob who doesnt understand vectors :/ Code: WitherSkull wither = player.launchProjectile(WitherSkull.class); wither.setShooter(event.getPlayer()); wither.setVelocity(event.getPlayer().getEyeLocation().getDirection().multiply(1)); WitherSkull wither2 = player.launchProjectile(WitherSkull.class); wither2.setShooter(event.getPlayer()); wither2.setVelocity(event.getPlayer().getEyeLocation().getDirection().multiply(1)); WitherSkull wither3 = player.launchProjectile(WitherSkull.class); wither3.setShooter(event.getPlayer()); wither3.setVelocity(event.getPlayer().getEyeLocation().getDirection().multiply(1));
@mythbusterma Yes.Thank you for answering. @mythbusterma Yes, that is what I want to do. Right now they just go all in the same direction.I tried adding a vector but that didnt work out so well she went always to the same direction even if the player wasnt looking to that direction.Also do you know if the guardian beam is a projectile? @mythbusterma What if i get the the vector of the direction that the player is looking and then modify it, would that work? The only problem is that I don´t know how to modify it I just know how to get it. If you could help it would be great if not I´ll just keep trying to find a solution. Code to get the player direction vector: Code: Vector direction = Player.getLocation().getDirection(); EDIT by Timtower: merged posts, please use the edit button instead of double posting.
Get the player's view direction and rotate the vector 90 degrees to the left (right). Rotating by 90 degrees is simple: Vector (x,y,z) 90 degrees rotated to the left becomes (-z,y,x), rotated to the right becomes (z,y,-x).
@mjra007 Please don't double (triple) post. If you have something else to say, click the "Edit" button and add what you want instead of making 3 different comments
@blablubbabc I tried this Code: Vector original = player.getEyeLocation().getDirection(); Vector right = new Vector(original.getX()-180, original.getY(), original.getZ()); Vector left = new Vector(original.getX(), original.getY(), original.getZ()-180); WitherSkull wither = player.launchProjectile(WitherSkull.class); wither.setShooter(event.getPlayer()); wither.setVelocity(right.multiply(1)); WitherSkull wither2 = player.launchProjectile(WitherSkull.class); wither2.setShooter(event.getPlayer()); wither2.setVelocity(original.multiply(1)); WitherSkull wither3 = player.launchProjectile(WitherSkull.class); wither3.setShooter(event.getPlayer()); wither3.setVelocity(left.multiply(1)); But it didnt work I could only see one skull the one that has the original vector.Maybe there is another way to do this.Please, I could use some help.is there a rotate() ? @boomboompower Sorry, I´ll do it next time EDIT by Timtower: merged posts, please use the edit button instead of double posting. Yet you did it again EDIT2: Sorry Timtower :/ I thought as it was two different things...Well now I know. @blablubbabc I think the skulls are exploding in my face the other two. EDIT3: The problem is that the x doesnt come in degrees what was i thinking?@blablubbabc is there a simple way to rotate the x like rotate() <--- that didnt seem to be something
See my post above. Actually in minecraft it seems to be slightly different due to minecraft's coordinate system being slightly different: Vector (x,y,z) 90 degrees rotated to the left becomes (z,y,-x), rotated to the right becomes (-z,y,x). Vector original = player.getEyeLocation().getDirection(); Vector right = new Vector(-original.getZ(), original.getY(), original.getX()); Vector left = new Vector(original.getZ(), original.getY(), -original.getX()); Alternatively you can rotate vectors around the y axis by any angle you want this way, however the above methods are more performant if you only need 90 degree rotations: Code: /** * Rotates the given vector around the y axis. * This modifies the given vector. * * @param vector * the vector to rotate * @param angleD * the angle of the rotation in degrees * @return the given vector rotated */ public static Vector rotateYAxis(Vector vector, double angleD) { // Validate.notNull(vector); if (angleD == 0.0D) return vector; double angleR = Math.toRadians(angleD); double x = vector.getX(); double z = vector.getZ(); double cos = Math.cos(angleR); double sin = Math.sin(angleR); vector.setX(x * cos + z * (-sin)); vector.setZ(x * sin + z * cos); return vector; }