2011-11-28 68 views
0

我想在我的XNA游戏中实现转向行为,主要是在那里,但可以用一些小东西。这些行为工作得很好,我的问题在于更新的时间和大小。转向行为工作得太快

(我用SharpSteer(几乎全是在这一点),它可以在这里找到:

http://sharpsteer.codeplex.com/SourceControl/changeset/view/18102

的Update()方法是我很努力。目前我使用这个方法(直接从SharpSteer)

// apply a given steering force to our momentum, 
    // adjusting our orientation to maintain velocity-alignment. 
    public void ApplySteeringForce(Vector3 force, float elapsedTime) 
    { 
     Vector3 adjustedForce = AdjustRawSteeringForce(force, elapsedTime); 

     // enforce limit on magnitude of steering force 
     Vector3 clippedForce = Vector3Helpers.TruncateLength(adjustedForce, MaxForce); 

     // compute acceleration and velocity 
     Vector3 newAcceleration = (clippedForce/Mass); 
     Vector3 newVelocity = Velocity; 

     // damp out abrupt changes and oscillations in steering acceleration 
     // (rate is proportional to time step, then clipped into useful range) 
     if (elapsedTime > 0) 
     { 
      float smoothRate = Utilities.Clip(9 * elapsedTime, 0.15f, 0.4f); 
      Utilities.BlendIntoAccumulator(smoothRate, newAcceleration, ref acceleration); 
     } 

     // Euler integrate (per frame) acceleration into velocity 
     newVelocity += acceleration * elapsedTime; 

     // enforce speed limit 
     newVelocity = Vector3Helpers.TruncateLength(newVelocity, MaxSpeed); 

     // update Speed 
     Speed = (newVelocity.Length()); 

     // Euler integrate (per frame) velocity into position 
     Position = (Position + (newVelocity * elapsedTime)); 

     // regenerate local space (by default: align vehicle's forward axis with 
     // new velocity, but this behavior may be overridden by derived classes.) 
     RegenerateLocalSpace(newVelocity, elapsedTime); 

     // maintain path curvature information 
     MeasurePathCurvature(elapsedTime); 

     // running average of recent positions 
     Utilities.BlendIntoAccumulator(elapsedTime * 0.06f, // QQQ 
           Position, 
           ref smoothedPosition); 
    } 

这工作,但更改帧与帧的是巨大的,由于经过的时间乘数(我认为SharpSteer使用它自己的比赛计时钟,而不是gameTime,我正在使用gameTime)

我正在寻找一种方法来减慢很多,并使用速度值的范围大于1.0f。

目前我使用1.0f的速度和1.0f的maxForce。我注意到Velocity始终为(0,0,0),elapsedTime为16(这称为每秒60次) smoothRate始终为0.4f,同样因为elapsedTime太大。

如果有人可以帮助平衡车辆的速度有点我会很感激。

回答

1

提高质量会挫伤的进入方法相同的力(减速)加速。你确定你有适当的质量值?

此外,您的速度代表单位每秒?如果是这样,那么16毫秒的经过时间应该是0.016;

0

仔细查看代码,并用相应的测量单位标记/重命名每个时间并将相关变量/参数加速。很可能你会发现你要么混合秒和毫秒,要么是某种距离/每秒不匹配。

样品名称:

public void ApplySteeringForce(Vector3 force, float elapsedTimeInSeconds) 
Vector3 newVelocity = Velocity; // Pixel per Millisecond