I would like to rotate an object along a curve. I managed to move the object along the curve using bezier curve algorithm. The hard part is to rotate the object constantly(no limit on maximum angle), and have to land at the end position. The angle have to be multiply of 360 when it land on the end position. A good example would be Maplestory, the item is dropped when a monster is killed. The item is rotated constantly and it will always landed at the correct angle. Start position and End position will be provided, as is used by the bezier curve algorithm, is there any algorithm for the rotation part?
First, choose your starting and ending angles by any method you choose (they could be fixed constants, or one or both could be randomized or computed from the other...)
Next, compute the angular difference between them, wrapped to +- 180 degrees. eg...
float angleDifference = fmod(endAngle - startAngle + 900.0f, 360.0f) - 180.0f;
Next, when you compute your new position using a parameter
0 <= t <= 1 passed as an argument to your Bezier curve function, use the same parameter to interpolate your angle:
position = EvaluateBezier(startPosition, controlPoint, endPosition, t);
angle = fmod(startAngle + t * angleDifference + 360.0f, 360.0f);
This ensures you rotate at a constant rate over the course of the motion, and end with the angle exactly at your desired
If you prefer to have the motion ease out, you can do so by applying the easing function of your choice to the parameter
t before using it to interpolate your angle.