车辆控制器转向力实现异常:车辆失控漂浮问题求助
自定义车辆控制器转向力实现问题
我正跟随Very Very Valet的教程编写自定义车辆控制器(以熟悉游戏物理),但在实现转向力时遇到困难。
目前我的代码如下:
private void _steering() { var tyreTransform = transform; Vector3 steeringDirection = tyreTransform.right; Vector3 tyreWorldVelocity = _carRigidbody.GetPointVelocity(tyreTransform.position); float steeringVelocity = Vector3.Dot(steeringDirection, tyreWorldVelocity); // 100% grip for now float desiredVelocityChange = -steeringVelocity * 1f; float desiredAccelerationChange = desiredVelocityChange / Time.fixedDeltaTime; var appliedForce = desiredAccelerationChange * _configuration.tyreMass * steeringDirection; _carRigidbody.AddForceAtPosition(appliedForce, tyreTransform.position); }
该方法在每个车轮节点的FixedUpdate()中调用(需通过地面接触检测确保车轮触地)。我确信已正确遵循教程,但出现了异常行为:车辆不可预测地漂浮,且转向功能异常。由于我对游戏编程不够熟悉,无法自行排查问题,恳请提供帮助。
补充说明:我使用了教程推荐的各项车辆参数:轮胎质量为10,车辆质量为100。
内容的提问来源于stack exchange,提问作者Bravetheif
相关产品推荐
相关产品推荐

