Jump to content

player rotation


Jdb100

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

    }

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.