我有一个汽车对象,我希望它逐渐旋转到用户点击的方向。
我用数学的每一帧来计算它需要的新方向,并将其存储在car.direction中。实际的方向当然是car.rotation。
现在我想每帧更新一次旋转,直到它等于方向。然而,我尝试了一切,无法弄清楚如何做到这一点。
顺便说一下,我正在使用FireFly,这是一个建立在Starling Framework之上的游戏引擎,但我不认为它是相关的。
答案 0 :(得分:1)
我会选择Marty的建议,使用smallestAngle函数来确定你应该旋转的方向。基本上你可以在每次帧更新期间移动一小部分的最小角度,直到那个最小角度的百分比低于某个阈值(并且让它“快速”完成剩下的部分)。
像
这样的东西//each time this is called it will get 1/4 closer, but never get to 0, hence the need for a threshold avoid paradoxes
//http://en.wikipedia.org/wiki/Zeno's_paradoxes#Dichotomy_paradox
var angleToMove:Number = smallestAngle()/4; //the divide by 4 here means get 1/4 of the angle gap closer each time this function is called, I assume this is on a timer or frame handler, making the 4 greater will make it follow more slowly, making it lower will make it follow more quickly, never reduce to or below 0 unless you want wonkiness
if(angleToMove<someRadianThreshold)
angleToMove = smallestAngle();
//use angleToMove to adjust the current heading/rotation