public void Init(BoatController controller)
        {
            _controller = controller;
            Vector3 scale = transform.localScale;

            _maxWeight = -scale.x * scale.y * scale.z * _weightBase;
            enabled    = true;
        }
Пример #2
0
        public void Init(BoatController controller)
        {
            _controller = controller;

            // 计算相对质心的位置
            Vector3 relativePosition = _controller.transform.InverseTransformPoint(_pivot.position) - controller.rigidbody.centerOfMass;

            if (relativePosition.z < 0)
            {
                _steerAngle = -_steerAngle;
            }

            _steerFactor = (transform.localScale.y + transform.localScale.z) * _steerFactor * (float)(Math.Log(_controller.rigidbody.mass / 6666 + 1f) * 6666);

            enabled = true;
        }
Пример #3
0
        public void Init(BoatController controller, bool isSubmarine)
        {
            _controller     = controller;
            _forceDirection = GetDirection(transform.localRotation * Vector3.forward);
            _maxForce       = (transform.localScale.x + transform.localScale.y) * 0.5f * _forceFactor;

            // 计算相对质心的位置
            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;
            float cos = Vector3.Dot(Vector3.forward, _localAngularDirection);

            // 计算力应用位置和旋转方向
            if (_forceDirection == Direction.Up || _forceDirection == Direction.Down)
            {
                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 prjectCenter = Vector3.ProjectOnPlane(controller.rigidbody.worldCenterOfMass, Vector3.Cross(Vector3.up, transform.forward));
                Vector3 newPivot, whatever;
                Utility.ClosestPoint(
                    _forcePivot.position + new Vector3(0, 20, 0), _forcePivot.position + new Vector3(0, -20, 0),
                    prjectCenter + transform.forward * 20, prjectCenter - transform.forward * 20,
                    out newPivot, out whatever);

                _forcePivot.position = (newPivot + _forcePivot.position) * 0.5f;
            }
            else
            {
                _rotateRight = cos > 0;
                _rotateLeft  = cos < 0;

                Vector3 _forceApplyPoint = controller.rigidbody.centerOfMass;
                _forceApplyPoint.x  += relativePosition.x;
                _forceApplyPoint.z  += relativePosition.z;
                _forcePivot.position = _controller.transform.TransformPoint(_forceApplyPoint);
            }

            enabled = isSubmarine ? true : (_forceDirection != Direction.Up && _forceDirection != Direction.Down);
        }