Posted January 22, 201312 yr Ok before anything i want to say i know there is rotation pitch and yaw ok anyways what i am trying to do is get the players rotation and make the player move 10 blocks in that direction so basically how do you get a players rotation and move them in that direction Creator of Jobo's ModLoader If I helped you could you please click the thank you button and applaud my karma.
January 24, 201312 yr If I remember rightly, if you do double a = Math.toRadians(player.rotationYaw); double dx = -Math.sin(a); double dz = Math.cos(a); then (dx, dz) is a unit vector pointing in the direction the player is facing in the X-Z plane. Multiply that by the distance you want to move.
January 27, 201312 yr Author I might have done something wrong public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { double a = Math.toRadians(par3EntityPlayer.rotationYaw); double dx = -Math.sin(a) * 10; double dz = Math.cos(a) * 10; par3EntityPlayer.posX = dx; par3EntityPlayer.posZ = dz; return par1ItemStack; } Creator of Jobo's ModLoader If I helped you could you please click the thank you button and applaud my karma.
February 1, 201312 yr You need to add dx and dz to the player's current position, not just set them. However, that probably isn't the right thing to do either, as it will attempt to teleport the player to the new position, regardless of whether there are any obstacles in the way, and also regardless of whether there is an empty space at the new position. If you teleport a player into a solid mass of blocks, he will get stuck and suffocate. To move the player while taking collisions into account, use the moveEntity method: player.moveEntity(dx, 0, dz); If you really want to teleport the player, the right way is to call setPositionAndUpdate: player.setPositionAndUpdate(player.posX + dx, player.posY, player.posZ + dz); This will ensure that the new position is communicated correctly to the client side.
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.