我想让一个物体从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个向量相加。。然后移动物体
}数学老师死的早,还请见谅、、、
不知道错在哪里求指教
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个向量相加。。然后移动物体
}数学老师死的早,还请见谅、、、
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货