Jump to content

Recommended Posts

Posted

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?

Posted

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.

Posted (edited)
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 :D (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:

image.png.0b41e314b8d4143ada9f3705efb8fca0.png

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

Edited by Ardno
Posted

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.

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.