# [1.16.3] How to calcule line in 3D

## Recommended Posts

Hello,

I'm trying to get the fastest way (line) from one pitch and yaw to another pitch and yaw in 3d space and rotate entity on this line. Is there any way to do this smoothly? Not with jerky movement?

##### Share on other sites

That's not a line, that's a sphere. You want to look up how to calculate a Slerp (spherical linear interpolation).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

DO NOT PM ME WITH PROBLEMS. No help will be given.

##### Share on other sites

21 minutes ago, Draco18s said:

That's not a line, that's a sphere. You want to look up how to calculate a Slerp (spherical linear interpolation).

Ehhh probabbly yes, but in 3d  (I only want to rotate with entity's head from A (pitch=0f,yaw=90f) to B (pitch=-10),yaw=5). Can you please send me example, because this mathematical example:

is really hard and I don't know how to calculate it and use in real case.

Edited by Ardno
##### Share on other sites

Howdy

That Slerp is something different, nothing to do with what you are trying to do.

For low values of pitch, you can get a smooth motion like this.

Initial position: yaw0 pitch0 time0

Final position: yaw1 pitch1 time1

each tick:

the time is timeX  (starts initially at time0, finishes at time1)

yawX = yaw0 + (time - time0) *  (yaw1 - yaw0) / (time1 - time0)

pitchX = pitch0 + (time - time0) *  (pitch1 - pitch0) / (time1 - time0)

If you want the acceleration and deceleration to be smooth as well, it gets trickier but not a lot trickier.  You just need to define a new variable progress

time0 = start of acceleration

time1 = end of acceleration, start of constant speed

time2 = end of constant speed, start of deceleration

time3 = end of deceleration

during acceleration:

progress = 0.5 * A * (timeX - time0)^2

during constant speed:

progress =  0.5 * A * (time1 - time0)^2 +  S * (timeX - time1)

during deceleration:

progress = 0.5 * A * (time1 - time0)^2 +  S * (timeX - time1) - 0.5 * D * (timeX - time2)^2

and then calculate eg

yawX = yaw0 + (progress- progress0) *  (yaw3 - yaw0) / (progress3- progress0)

You choose A, D, and S depending on how fast you want the acceleration, coasting speed, and deceleration to be.

There are some constraints

i.e.

S = (time1 - time0) * A.

and you need to check for the case that there is no constant speed (i.e. you start accelerating but don't reach steady speed before having to start decelerating.)

If you have high values of pitch (say 60 degrees or more) then the motion will speed up or slow down a bit (faster near pitch 0, slower near pitch 90) but it will still look smooth and it's probably not worthwhile going into the more-complicated maths (sin, cos, and/or Quaternions) that you would need.

Cheers

TGG

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

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 previous content has been restored.   Clear editor

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

×

• ### Recently Browsing

• No registered users viewing this page.
• ### Posts

• i use fabric 1.20.1 i used alot of mods like all the trims, bobby, better stats, and more but i encounter a problem when i try to enter my world it force me to be in safe mode and when i click on safe mode it just crash minecraft
• So, I started a Forge server which is hosted by cloudnord (don't know it this information is necessary or not). Everything's working fine, the mods are getting loaded, I can join and play on it. Then I wanted to give myself OP. That's where the problems began. I typed "op mc_nicky_com" in the console and just saw, that I automatically disconnected... Weird, I thought and promptly updated the forge version to the client sided version, 47.2.17. Nothing resolved. Thought of downgrading the server to 47.2.0 but still didn't work. Now the server is on 47.2.0 and I can play without OP, which is totally fine but if I want to do something only OPs can do, I have to put it into the console, where I don't have auto-completion. The error it is throwing is the following: io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException: readerIndex(31613) + length(1) exceeds writerIndex(31613): UnpooledHeapByteBuf(ridx: 31613, widx: 31613, cap: 31613/31613) I don't know how to fix this and I am thankful for every help attempt that comes here.  With best regards nicky.gg

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...

## Important Information

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