Posted August 12, 201411 yr I want to make a projectile, extended from EntityThrowable, although it wont be thrown but it will have the same mechanics. This projectile will only appear when the player is looking at a block. I want this projectile to reach the center of the block in a straight line, so I don't want to have the player's pitch and yaw as the projectile's but rather I want the pitch and yaw that will make the projectile reach the center of the block, but I can't seem to figure out how I would calculate the pitch and yaw of the projectile, as I don't know a lot about rotations. Can someone help?
August 12, 201411 yr Look into Math.atan2(y, x) -- it will return an angle given a vector from origin. Calculate the vector by the difference between player position and the position of the target looked at (use a ray-trace for getting that position). A good article explaining many of the basic geometric concepts related to angles/positions: http://www.helixsoft.nl/articles/circle/sincos.htm
August 13, 201411 yr Hi You might find these posts useful http://www.minecraftforge.net/forum/index.php/topic,18543.msg93804.html#msg93804 http://www.minecraftforge.net/forum/index.php/topic,18682.msg94603.html#msg94603 and https://www.chrobotics.com/library/understanding-euler-angles -TGG
August 13, 201411 yr Author I've got it sorted out by doing so: double degree = 180 / Math.PI; double dx = player.posX - (playermop.blockX + 0.5); double dy = (player.posY + player.eyeHeight) - (playermop.blockY + 0.5); double dz = player.posZ - (playermop.blockZ + 0.5); double yaw = -((Math.atan2(dx, dz) * degree) + 180); double pitch = (Math.atan2(dy, Math.sqrt(dx * dx + dz * dz)) * degree); I wanted it in degrees to compare it with player's rotationYaw and rotationPitch and it worked perfectly, it gives the exact yaw and pitch if the player is looking at the center of the block. I just want to know if it is theoretically correct to do it like so...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.