   Parabolic motion smoothing
  I've got sprites turning to face the position of a mouse click, and I can even define the angular speed, but what I'm lacking is a way to smoothly accelerate toward a maximum speed, and decelerate from there.The best idea my mathematically handicapped mind can conjure is to somehow use a parabola to smooth out the motion.  My X axis would be the remaining difference between my current rotation and the final rotation, and my Y axis would be the speed at that point.  vertex = (0, max_speed)x-intercept = (rotation_diff / 2, 0)So if I have a max speed of 1.0 degrees per millisecond, and a difference of 30 degrees to cover:y = -.0044(x - 0)^2 + 1.0I basically just want my ships to start turning slowly, speed up, and then gradually slow down as they zero in on the new facing.I'm a little worried that for a wide angle rotation, it might take too long to "get up to speed", and to slow down.  Before I go about implementing this, I wanted to ask if anyone has better ideas, or has tried this and it turned out to be an awful solution.   
  You could try using an exponential function for the angle (not ang velocity), something like:1-exp(-x*5)On the 0-1 interval it increases quite fast at start and slows down quite a lot at the end.Now if you have a full flown physics engine in there and you don't want to/can't prod the angle straight away, you can get something like this with Forces/Drags.Let's say the maximum velocity is 'vmax' and the time to reach it is 'tmax'.Apply a torque that is equal to vmax*f*deltaAngle*C where f is a constant I'll get back to later. Delta Angle is the difference between the current angle and the final angle (how much you want to rotate).The apply a drag torque that is D = v*C. Where C = -log(0.01) / tmax. This expression gives a drag coefficient that will allow acceleration/braking from 0 to vmax in exactly tmax with 1% error. Thus you have: T = vmax*f*deltaAngle*C - v*C. v = v + F*dt angle = angle + v * dt;and deltaAngle = angleWant - angleCurrentThe choice of f gives either a wobbly but faster rotation towards the desired angle or a slower but stable rotation towards it. The fastest stable rotation is obtained for f = C / (4*vmax)All from here.;Quote:Original post by ZeugmalI've got sprites turning to face the position of a mouse click, and I can even define the angular speed, but what I'm lacking is a way to smoothly accelerate toward a maximum speed, and decelerate from there.The best idea my mathematically handicapped mind can conjure is to somehow use a parabola to smooth out the motion.  My X axis would be the remaining difference between my current rotation and the final rotation, and my Y axis would be the speed at that point.  vertex = (0, max_speed)x-intercept = (rotation_diff / 2, 0)So if I have a max speed of 1.0 degrees per millisecond, and a difference of 30 degrees to cover:y = -.0044(x - 0)^2 + 1.0I basically just want my ships to start turning slowly, speed up, and then gradually slow down as they zero in on the new facing.I'm a little worried that for a wide angle rotation, it might take too long to "get up to speed", and to slow down.  Before I go about implementing this, I wanted to ask if anyone has better ideas, or has tried this and it turned out to be an awful solution.I recently had to write some code to do what you're describing. I used some simple calculus to handle the deceleration (the method I used may be equivalent to your 'parabolic' method, but I'd have to examine it more closely to be sure).If you're still stuck on this, I could post my code for handling this. (It wouldn't be cleaned up though, so you'd probably have to work with it a bit to adapt it to your needs - fair warning! :)   ;  Thank you for the suggestions.  I'm actually having a little trouble implementing my smoothing algorithm, but I think I'm going to move on to other parts of the game before I get too frustrated.  One lesson I've learned here is that I'm definitely going to need to improve my mathematical abilities if I want to get very far with game programming.   ;  If all you want is smooth motion, there are lots of ways.--- Method 1:The particular method you seemed to want to use was,1 - Have bounded acceleration and velocity.2 - Get to the desired orientation as quickly as possible, with this bounded acceleration and velocity.The solution to this problem is to accelerate as hard as possible until you have to begin decelerating so you come to rest at the desired angle.  I.e., you floor the gas pedal until you have to start braking -- at which point you brake as hard as you can.You should note that what you get by doing this is not a single parabola.  Rather, it's a piecewise function in either two or three pieces -- most generally, three:1 - A concave-up parabolic section, as the body accelerates up to top angular velocity.2 - A linear section going up, as the body continues to move at maximum velocity.3 - A concave-down parabolic section, as the body decelerates to rest.The second section may not be there if you are only rotating a short distance and never get up to maximum velocity.I won't work out the solution to this problem for you, but it's something you should be able to figure out without too much trouble.-- Method 2:You could also use any spline you wanted to join your points.- 2a:One appealing choice would be a cubic spline, which gives the minimum-energy (lowest RMS value of acceleration) solution, for a fixed transit time.  Cubic splines have four degrees of freedom.  You would impose the following constraints: 1 - The initial value of the spline is the starting angle. 2 - The final value of the spline is the end angle. 3 - The initial slope of the spline is zero. 4 - The final slope of the spline is zero.Note that when I say "final value" this assumes that you have decided a priori how long it should take for the rotation to happen.- 2b:You could also use cosine interpolation.  E.g.,f(t) = theta(t1) + (1/2)(theta(t2) - theta(t1))(1 - cos(t))has zero initial and final velocity, and will get you between the two angles in pi seconds.   