我有一个精灵,它跟踪并跟随屏幕上的对象,向它们移动。
该方法按计划运行,基本上如下所示:
- (void) nextFrame:(ccTime)dt {
//calculate distance between the bubble and the fish
float dx = bubbleToChase.position.x - fish.position.x;
float dy = bubbleToChase.position.y - fish.position.y;
float d = sqrt(dx*dx + dy*dy);
float v = 400;
if (d > 190){
NSLog(@"moving the fish!");
fish.position = ccp( fish.position.x + dx/d * v *dt,
fish.position.y + dy/d * v *dt);
}
}
该代码运行良好,当距离大于 190 时,鱼会游向它。
问题是对象具有物理特性,因此它们在屏幕上滑动。这会对鱼精灵产生一种摇晃/交错的效果,因为鱼一旦到达气泡就会停下来,但是随着气泡逐渐漂移 (d > 190),它会摇晃并迅速停止。
我怎样才能摆脱这种跳汰效应?一旦鱼到达气泡的位置,我想阻止它移动。或者任何可以平滑它的替代方案。任何帮助表示赞赏,谢谢。