@@ -189,8 +189,14 @@ public float SidewaySlipMultipler
189
189
/// In the plane, output the force that will result in this acceleration.
190
190
/// On a slope, it is affected by the slope resistance, so it does not match the input.
191
191
/// </summary>
192
- // TODO: Compute first order lag
193
- public float AccelerationInput ;
192
+ public float AccelerationInput
193
+ {
194
+ get => acceleration . DesiredValue ;
195
+ set => acceleration . DesiredValue = Mathf . Clamp ( value , - MaxAccelerationInput , MaxAccelerationInput ) ;
196
+ }
197
+ private FirstOrderLaggedFloat acceleration ;
198
+ [ SerializeField , Min ( 0.0f ) , Tooltip ( "Set 0 to disable the lag" ) ]
199
+ private float accelerationTimeConstant = 0.0f ;
194
200
195
201
/// <summary>
196
202
/// Vehicle steering input. Tire angle (degree)
@@ -215,6 +221,11 @@ public float SteerAngleInput
215
221
/// </summary>
216
222
public Vector3 LocalAcceleration { get ; private set ; }
217
223
224
+ /// <summary>
225
+ /// Vehicle acceleration (m/s^2)
226
+ /// </summary>
227
+ public float Acceleration => acceleration . Value ;
228
+
218
229
/// <summary>
219
230
/// Vehicle speed (m/s)
220
231
/// </summary>
@@ -303,6 +314,9 @@ void Awake()
303
314
ForwardSlipMultipler = 1f ;
304
315
SidewaySlipMultipler = 1f ;
305
316
317
+ // Initialize acceleration
318
+ acceleration = new FirstOrderLaggedFloat ( accelerationTimeConstant , 0.0f ) ;
319
+
306
320
// Initialize steer angle
307
321
steerAngle = new FirstOrderLaggedFloat ( steerAngleTimeConstant , 0.0f ) ;
308
322
}
@@ -331,9 +345,6 @@ private void OnTriggerExit(Collider other)
331
345
332
346
void FixedUpdate ( )
333
347
{
334
- // Clamp input values.
335
- AccelerationInput = Mathf . Clamp ( AccelerationInput , - MaxAccelerationInput , MaxAccelerationInput ) ;
336
-
337
348
// Compute vehicle infomation.
338
349
ComputeVehicleState ( ) ;
339
350
@@ -347,8 +358,7 @@ void FixedUpdate()
347
358
if ( sleep == false )
348
359
{
349
360
// Update wheel force.
350
- var acceleration = AccelerationInput ;
351
- UpdateWheelsForce ( acceleration ) ;
361
+ UpdateWheelsForce ( Acceleration ) ;
352
362
}
353
363
354
364
// cache value for next frame.
0 commit comments