我想在我的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太大。
如果有人可以幫助平衡車輛的速度有點我會很感激。