Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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.

  • 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;

    }

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.