追踪算法的原理:目标位置 - 当前位置 / 速度,即: dx = targetX - currentX / speed, dy = targetY - currentY / speed
var getStep = function(iTarget, iNow) { var iStep = (iTarget - iNow) / this.speed; if (iStep == 0){ return 0; } if (Math.abs(iStep) < 1){ return (iStep > 0 ? 1 : -1); } return iStep; }; var dx = getStep(this.ctx.owner.owner.player.x,this.ctx.owner.x), dy = getStep(this.ctx.owner.owner.player.y,this.ctx.owner.y);
时间: 2024-10-12 22:29:03