Prediction and angles
BlitzMax Forums/BlitzMax Programming/Prediction and angles
| ||
I'm using prediction in a network game, everytime a packet arrives it calculates the averate angle rate by dividing the angle difference by the duration of frames. This works fine for angles like 30 to 50, but when there happens to be a 359 -> 2 angle change, it of course calculates it to be something like 357/frames, even though the correct prediction is 3/frames. Is there better fix to this than to just limit the max angle difference? |
| ||
Use quaternions, on which you can use spherical interpolation, and the issue will not arise. |
| ||
Quick idea, if it is greater then 180 then subtract 360 from the result. In this case it would be 357 > 180 so 360 - 357 = 3 I'm pretty sure I'm missing something important though... |
| ||
If there is more than 180 degrees difference between the angles, add 360 to the smallest value? |
| ||
function nicedifference#(an1#,an2#) an=(an2-an1) mod 360 if an < -180 then an=an+360 if an > 180 then an=an-360 return an end function |
| ||
Yup, Xlsior and Warpy got the part I was missing. |
| ||
Thanks, that seems to work. |