C# 线性移动对象的未来位置

C# 线性移动对象的未来位置,c#,unity3d,game-physics,C#,Unity3d,Game Physics,物体以8的起始速度(SP)线性向前移动,其加速度为每秒0.02fSP为游标速度=分钟速度 (1) minSpeed=8 (2) maxSpeed=20 (3) curSpeed+=加速度*时间.延迟时间-直到达到最大速度 10、15或30秒后对象将在何处? 我需要在几秒钟后从当前玩家位置到未来位置提前生成一个对象,以同步游戏。假设玩家处于零,10秒后距离为90,我将在90之前生成对象,让玩家捕捉。有人知道如何解决这个问题吗?它可以用数学来解决,但我有另一个想法。将空游戏对象作为移动对象的子对象。

物体以8的起始速度(SP)线性向前移动,其加速度为每秒0.02f<代码>SP为游标速度=分钟速度 (1)
minSpeed=8
(2)
maxSpeed=20
(3)
curSpeed+=加速度*时间.延迟时间
-直到达到最大速度 10、15或30秒后对象将在何处?
我需要在几秒钟后从当前玩家位置到未来位置提前生成一个对象,以同步游戏。假设玩家处于零,10秒后距离为90,我将在90之前生成对象,让玩家捕捉。有人知道如何解决这个问题吗?

它可以用数学来解决,但我有另一个想法。将空游戏对象作为移动对象的子对象。按所需距离沿移动方向移动。在脚本中使用

public Transform spawnPoint
并将其分配给检查员。现在,您可以在
繁殖点提前繁殖对象。无论速度或时间如何,它都将与您的玩家保持相同的距离

数学解决方案: 首先,您需要将开始位置存储到矢量3。让我们称之为
startPos
。然后我们需要一个运动方向向量。例如(但这取决于你的动作)

然后你会说两种运动:加速和线性

让我们计算加速时间:

float aTime = (maxSpeed - minSpeed)/acceleration;
让我们计算加速度结束的位置:

Vector3 aEndPos = startPos + direction * (minSpeed * aTime + acceleration * Mathf.Pow(aTime, 2) / 2f);
现在我们可以编写计算距离的方法:

Vector3 GetDistance(float time)
{
  Vector3 direction = Vector3.forward;
  float aTime = (maxSpeed - minSpeed)/acceleration;
  Vector3 aEndPos = startPos + direction * (minSpeed * aTime + acceleration * Mathf.Pow(aTime, 2) / 2f);

  if (time <= aTime) //if we are in accelerating movement
  {
      return startPos + direction * (minSpeed * time + acceleration * Mathf.Pow(time, 2) / 2f);
  } 
  else // we are in linear
  {
      return aEndPos + direction * maxSpeed * (time - aTime)
  }
}
Vector3获取距离(浮动时间)
{
Vector3方向=Vector3.forward;
浮动时间=(最大速度-分钟速度)/加速度;
Vector3 aEndPos=开始时间+方向*(分钟速度*时间+加速度*数学功率(时间,2)/2f);

如果(时间,谢谢你的解决方案。它可能在一些情况下工作,比如如果需要在离播放器几米远的地方繁殖,如(5,10,20)。实际上我需要与音乐节拍同步繁殖。例如,我有一个120秒长的音频,其中节拍发生在(2.2),(8.2),(9.93),(11.2),(11.5)等等。这是我正在研究的图表和数学解
Vector3 GetDistance(float time)
{
  Vector3 direction = Vector3.forward;
  float aTime = (maxSpeed - minSpeed)/acceleration;
  Vector3 aEndPos = startPos + direction * (minSpeed * aTime + acceleration * Mathf.Pow(aTime, 2) / 2f);

  if (time <= aTime) //if we are in accelerating movement
  {
      return startPos + direction * (minSpeed * time + acceleration * Mathf.Pow(time, 2) / 2f);
  } 
  else // we are in linear
  {
      return aEndPos + direction * maxSpeed * (time - aTime)
  }
}