Jump to content

[1.8] [SOLVED] How to make a player face a block


SnowyEgret

Recommended Posts

Hi  :),

 

I am trying to make the player orbit around a block.  I would like to have the player always face the block at the center of the orbit. I've been messing around with:

 

player.setPosition(x, y, z);
player.setPositionAndRotation(x, y, z, yaw, pitch);
player.setPositionAndUpdate(x, y, z);
player.setLocationAndAngles(x, y, z, yaw, pitch);

 

Setting the position seems to be working ok. I am having problems setting the direction the player is looking. Ideally I would be looking for something like:

 

player.setLocation(double x, double y, double z);
player.facePosition(BlockPos pos);

 

When you hit f5, minecraft behaves like this, except I want a block at the center of the view. Any help is appreciated :)

Link to comment
Share on other sites

I suppose some mathematic calculations should be applyed to get pitch and yaw.

double x = player.posX - blockPos.getX() - 0.5;
double y = player.posY - blockPos.getY() - 0.5;
double z = player.posZ - blockPos.getZ() - 0.5;
double pitch = Math.atan2(-y, Math.sqrt(x*x+z*z));
double yaw = Math.atan2(z, -x);

I forget the sign before

x

and

y

. You may try twice and get the correct ones.

Author of Tao Land Mod.

width=200 height=69http://taoland.herbix.me/images/1/14/TaoLandLogo.png[/img]

Also, author of RenderTo

----

I'm not an English native speaker. I just try my best.

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.