You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将AssettoCorsa读取的静止车辆SpeedKmh极小值修正为0

问题原因

SpeedKmh为float类型,你遇到的极小非零值属于游戏物理引擎浮点计算的正常精度误差,静止状态下的计算残留会输出远小于1的非零值。

实现逻辑

设置合理的速度判定阈值,通常取0.1km/h即可,只要读取到的SpeedKmh低于阈值就判定为静止,强制修正为0。可根据实际需求调整阈值大小。

代码修改方案

直接在ac_PhysicsUpdated物理数据更新回调中增加判断逻辑即可,修改后的回调代码如下:

static void ac_PhysicsUpdated(object sender, PhysicsEventArgs e)
{
    // 速度修正逻辑
    float originalSpeed = e.Physics.SpeedKmh;
    float correctedSpeed = originalSpeed < 0.1f ? 0f : originalSpeed;

    Console.WriteLine("  Speed:   " + correctedSpeed);
    //  Console.WriteLine("  Gear:   " + e.Physics.Gear);
    //  Console.WriteLine("  TC:   " + e.Physics.TC);
    Console.WriteLine("  RPM:   " + e.Physics.Rpms);
}

如果需要在多个位置调用修正后的速度,可以封装为扩展方法复用:

public static class PhysicsExtension
{
    public static float GetCorrectedSpeedKmh(this Physics physics, float stopThreshold = 0.1f)
    {
        return physics.SpeedKmh < stopThreshold ? 0f : physics.SpeedKmh;
    }
}

封装后调用方式为:

float speed = e.Physics.GetCorrectedSpeedKmh();
// 也可以自定义阈值
float speed = e.Physics.GetCorrectedSpeedKmh(0.05f);

内容的提问来源于stack exchange,提问作者montrey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 05:06:00