Jump to content

Recommended Posts

Posted

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?

Posted

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.

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.

Announcements



×
×
  • Create New...

Important Information

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