public void Init(HelicopterController controller) { _controller = controller; _forceDirection = GetDirection(transform.localRotation * Vector3.up); float radius = (transform.localScale.x + transform.localScale.z) * 0.5f * _originalRadius; _maxForce = _forceFactor * radius; // 计算加速度 _accelerate = Mathf.Pow(1.15f, -radius) * PEVCConfig.instance.rotorAccelerateFactor; _decelerate = Mathf.Pow(1.15f, -radius) * PEVCConfig.instance.rotorDecelerateFactor; // 相对质心的位置 Vector3 relativePosition = _controller.transform.InverseTransformPoint(_forcePivot.position) - controller.rigidbody.centerOfMass; // 前后位置 //_isFront = relativePosition.z > 0; // 计算旋转偏向 _localAngularDirection = Vector3.right; Vector3 relativeXZ = relativePosition; relativeXZ.y = 0; if (relativeXZ.sqrMagnitude > 0.25f) { _localAngularDirection = Vector3.Cross(Vector3.up, relativeXZ).normalized; } _localAngularDirection = Quaternion.Inverse(transform.localRotation) * _localAngularDirection; _localForwardDirection = Quaternion.Inverse(transform.localRotation) * Vector3.forward; float cos = Vector3.Dot(Vector3.up, _localAngularDirection); // 计算力应用位置和旋转方向 if (_forceDirection == Direction.Up) { float adjustedZ = Mathf.Sign(relativePosition.z) * Mathf.Log(Mathf.Abs(relativePosition.z) + 1f); adjustedZ = adjustedZ * PEVCConfig.instance.rotorBalanceAdjust + relativePosition.z * (1f - PEVCConfig.instance.rotorBalanceAdjust); adjustedZ *= PEVCConfig.instance.rotorBalaceScale.Evaluate(Mathf.Abs(adjustedZ)); Vector3 _forceApplyPoint = controller.rigidbody.centerOfMass; _forceApplyPoint.x += relativePosition.x; _forceApplyPoint.y += relativePosition.y; _forceApplyPoint.z += adjustedZ; _forcePivot.position = _controller.transform.TransformPoint(_forceApplyPoint); } else if (_forceDirection == Direction.Forward || _forceDirection == Direction.Back) { _rotateRight = cos > 0.5f; _rotateLeft = cos < -0.5f; Vector3 newPivot, whatever; Utility.ClosestPoint( _forcePivot.position + new Vector3(0, 100, 0), _forcePivot.position + new Vector3(0, -100, 0), controller.rigidbody.worldCenterOfMass + transform.up * 100, controller.rigidbody.worldCenterOfMass - transform.up * 100, out newPivot, out whatever); _forcePivot.position = newPivot; //if (_rotateRight || _rotateLeft) //{ // Vector3 _forceApplyPoint = controller.rigidbody.centerOfMass; // _forceApplyPoint.x += relativePosition.x; // _forceApplyPoint.z += relativePosition.z; // _forcePivot.position = _controller.transform.TransformPoint(_forceApplyPoint); //} //else _forcePivot.position = controller.rigidbody.worldCenterOfMass; } else { _rotateRight = cos > 0; _rotateLeft = cos < 0; } if (_forceDirection != Direction.Down) { enabled = true; } }