Ardno Posted December 6, 2020 Posted December 6, 2020 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? Quote
Draco18s Posted December 6, 2020 Posted December 6, 2020 That's not a line, that's a sphere. You want to look up how to calculate a Slerp (spherical linear interpolation). Quote 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.
Ardno Posted December 6, 2020 Author Posted December 6, 2020 (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 (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 December 6, 2020 by Ardno Quote
TheGreyGhost Posted December 7, 2020 Posted December 7, 2020 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 Quote
Recommended Posts
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.