我想让一个物体从A点慢慢移动到B点,但是结果非常奇怪我也知道怎么描述,总之就是动起来很奇怪
不知道错在哪里求指教
        public void Moving(object myParam)
        {
            this.TotalDistance = Math.Abs(Vector2.Distance(new Vector2(startX, startY), new Vector2(targetX, targetY)));
            this.radian = Math.Acos(targetX - startX / TotalDistance) / 180f * Math.PI;//目标地点和初始地点的弧度            float totalDistanceX = targetX - startX;
            float totalDistanceY = targetY - startY;            double distance = this.Owner.Speed * VariablesCommun.UpdateElapsed.ElapsedGameTime.TotalMilliseconds / 1000f;//这次应该移动多少距离            float distanceX = (float)(distance * Math.Cos(radian));//X轴上的距离
            if (totalDistanceX < 0)
                distanceX = -distanceX;
            float distanceY = (float)(distance * Math.Sin(radian));
            if (totalDistanceY < 0)
                distanceY = -distanceY;            this.Owner.MoveTo(Vector2.Add(this.Owner.GetCurrentPosition(), new Vector2(distanceX,distanceY)));//把2个向量相加。。然后移动物体
}数学老师死的早,还请见谅、、、

解决方案 »

  1.   

    其实假设一个点周围有8个点,你很容易判断这8个点哪一个离目标位置最近,然后直接移动到离目标最近的一个点上去就行了。根据速度不同,你可能不仅仅考虑8个点,而是周围更多点。但是道理一样。
      

  2.   

    实际上,你只需要进行整数计算,可能根本不需要什么浮点数、乘除法、三角函数之类的。
      

  3.   

    计算两点之间的距离,也没有必要使用乘法和开平方,只要(曼哈顿)求个绝对值相加就行了。