Hi guys, I need help calculating a vector for a particular use. I have already searched Google and found a calculation, but it requires Player's pitch to work and I need to force another object to move in the direction that the player is looking from a top down view, which means, the pitch is effectively zero, which leaves me with the Player's Yaw. Does anyone know of a good function / method that can use the Yaw and spit out a Correct Vector? I really only need the correct X and Z values of the vector.

That method also uses the pitch to return a vector to me. When my pitch is negligible, that calculation does not work either. Basically, I'm trying to get a vector that is similar to the location.getDirection() function without the need for the pitch, only the yaw.

Code (Java): /** * uses a player's yaw to calculate a value with a x and z value. * @returns The vector created from the player's yaw. */ private Vector yawToVector(Player player) { double radians = Math.toRadians(player.getLocation().getYaw()); double x = Math.sin(radians); double z = Math.cos(radians); return new Vector(-x, 0, z); }

Discard the y value. Code (Text): Vector direction = player.getLocation().getDirection(); direction.y = 0; direction.normalize();

Yes, this is why the player.getLocation().getDirection() was not the correct solution, because the underlying calculation requires the pitch, which is negligible when the player is looking straight down. Thanks everyone for your input, the correct solution was provided, THANKS!

@finnbon @VirusBrandon Before claiming what you think to be true as true, stop for a moment and think about what you guys are saying. "If I look straight down, my x and z directionals become 0". In other words, my character no longer has any horizontal orientation whatsoever. Does this mean I'm oriented to 360 degrees at the same time? Am I oriented to 0 degrees? Am I not oriented at all? Despite looking straight down, how is the server supposed to interpret in which direction my character is standing, how are other clients supposed to render my character, in which direction is the top of my head facing (assuming my face is facing straight down)? Even when facing straight down (or up) the x and z directionals never reach 0, otherwise I'd get stuck in something called gimbal lock. Sure they become really small, but that doesn't make a difference when normalizing vectors. Have a read, its quite interesting.

When you use location.getDirection(), you can move an object in the direction you are looking, but the object I am moving is on a 2-Dimenional, top-down view and getDirection.multiple(x) does not effect the object so when the velocity is changed for said object, pitch cannot be a deciding factor, which in your highlighted portion above, it is. @finnbon, hit it spot on.

@finnbon @VirusBrandon Both solutions do exactly the same thing. By setting the y-component of the vector to 0 we project it onto the XZ-plane. Renormalising the vector gives us a unit vector on the XZ-plane and effectively what Location.getDirection() would have returned if the pitch were to be 0.