void RumbleEffect(VehicleBase.WheelState ws, float linearPos, float factor) { // Compute a "virtual" bump height and apply a force pretending the // wheel is driving over it. float bumpHeight = amplitude * Triangle(linearPos, periodLength) * factor; float force = ws.wheelCol.runtimeSpringRate * bumpHeight; ws.wheelCol.runtimeExtraSuspensionForce = force; ws.wheelCol.ApplyForce(force * ws.hit.normal, ws.hit.point, ws.hit.collider.attachedRigidbody); }
public override void UpdateVehicleSuspension() { float speedFactor = Mathf.InverseLerp(noEffectsSpeed, fullEffectsSpeed, vehicle.speed); for (int i = 0; i < vehicle.wheelCount; i++) { VehicleBase.WheelState ws = vehicle.wheelState[i]; if (ws.grounded && ws.lastGroundHit.physicMaterial == rumbleMaterial) { m_wheelPos[i] += ws.localWheelVelocity.magnitude * Time.deltaTime; RumbleEffect(ws, m_wheelPos[i], speedFactor); } } }
public override void RecordData() { // Gather information int leftWheel = vehicle.GetWheelIndex(m_monitoredAxle, VehicleBase.WheelPos.Left); int rightWheel = vehicle.GetWheelIndex(m_monitoredAxle, VehicleBase.WheelPos.Right); VehicleBase.WheelState wsLeft = vehicle.wheelState[leftWheel]; VehicleBase.WheelState wsRight = vehicle.wheelState[rightWheel]; float averageSteerAngle = 0.5f * (wsLeft.steerAngle + wsRight.steerAngle); float yawRate = vehicle.cachedRigidbody.angularVelocity.y * Mathf.Rad2Deg; float roll = vehicle.cachedRigidbody.rotation.eulerAngles.z; if (roll > 180.0f) { roll -= 360.0f; } // Write to log m_steerAngle.Write(averageSteerAngle); m_yawRate.Write(yawRate); if (Mathf.Abs(roll) < 15.0f) { m_roll.Write(roll); } if (wsLeft.grounded) { m_leftCompression.Write(wsLeft.contactDepth * 1000.0f); } if (wsRight.grounded) { m_rightCompression.Write(wsRight.contactDepth * 1000.0f); } m_compressionDiff.Write((wsRight.contactDepth - wsLeft.contactDepth) * 1000.0f); if (MathUtility.FastAbs(averageSteerAngle) > 1.0f) { m_yawRateVsSteer.Write(yawRate / averageSteerAngle); } m_leftSpring.Write(wsLeft.wheelCol.lastRuntimeSpringRate); m_rightSpring.Write(wsRight.wheelCol.lastRuntimeSpringRate); }
public override void RecordData() { // Gather information VehicleBase.WheelState ws = vehicle.wheelState[monitoredWheel]; // Write to log if (ws.grounded) { m_contactDepth.Write(ws.contactDepth * 1000.0f); m_contactSpeed.Write(ws.contactSpeed * 1000.0f); m_suspensionForce.Write(ws.suspensionLoad); m_damperForce.Write(ws.damperForce); } m_suspensionTravel.Write(ws.wheelCol.suspensionDistance * 1000.0f); }