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

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?

Look into Math.atan2(y, x) -- it will return an angle given a vector from origin.

 

Calculate the vector by the difference between player position and the position of the target looked at (use a ray-trace for getting that position).

 

A good article explaining many of the basic geometric concepts related to angles/positions:

http://www.helixsoft.nl/articles/circle/sincos.htm

  • Author

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

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.