Ejemplo n.º 1
0
        public override void ManualUpdate(IOceanData data)
        {
            base.ManualUpdate(data);

            ControlInfo controlInfo = new ControlInfo();

            controlInfo.ForwardAxis = Input.GetAxis("Vertical");
            controlInfo.TurnAxis    = Input.GetAxis("Horizontal");

            foreach (var propeller in propellers)
            {
                PosAndForce force;
                if (propeller.TryGetForce(data, this, controlInfo, out force))
                {
                    AddForce(force);
                }
            }

            var horizontalForce = transform.right * rudder.horizontalPower * -controlInfo.TurnAxis;

            _rigidbody.AddForceAtPosition(horizontalForce, transform.TransformPoint(rudder.horizontalOffset));

            var verticalForce = transform.up * rudder.verticalPower * -controlInfo.ForwardAxis;

            _rigidbody.AddForceAtPosition(verticalForce, transform.TransformPoint(rudder.verticalOffset));
        }
Ejemplo n.º 2
0
        public virtual void ManualUpdate(IOceanData data)
        {
            int influenceDragCount = 0;
            int activatedDrag      = 0;

            foreach (var item in buoyancyData.Handles)
            {
                PosAndForce force;
                bool        isAddForce = item.TryGetForce(data, this, out force);

                if (isAddForce)
                {
                    AddForce(force);

                    if (item.IsInfluenceDrag)
                    {
                        influenceDragCount++;
                        activatedDrag++;
                    }
                }
                else
                {
                    if (item.IsInfluenceDrag)
                    {
                        influenceDragCount++;
                    }
                }
            }

            UpdateRigidbodyState(influenceDragCount, activatedDrag);
        }
Ejemplo n.º 3
0
        public bool TryGetForce(IOceanData data, BuoyancyObject sender, out PosAndForce value)
        {
            value = new PosAndForce();
            var   pos = value.Position = transform.TransformPoint(offset);
            var   distanceToSurface = data.DistanceToSurface(pos);
            float radius            = ActualRadius;

            if (distanceToSurface > radius)
            {
                return(false);
            }
            else
            {
                float scale = (radius - distanceToSurface) / (radius * 2);
                scale       = Mathf.Clamp01(scale);
                value.Force = data.Density * -Physics.gravity * scale * powerScale * sender.Power;
                return(true);
            }
        }
Ejemplo n.º 4
0
        public bool TryGetForce(IOceanData data, BuoyancyBoat sender, ControlInfo controlInfo, out PosAndForce value)
        {
            float radius            = effectiveRadius * UnityHelper.GetRadiusScaleFactor(transform.lossyScale);
            var   distanceToSurface = data.DistanceToSurface(transform.position);

            if (distanceToSurface > radius)
            {
                value = default;
                return(false);
            }
            else
            {
                var angle = transform.localEulerAngles;
                angle.y = LerpAxis(leftTurn, rightTurn, controlInfo.TurnAxis);
                transform.localEulerAngles = angle;

                float scale = (radius - distanceToSurface) / (radius * 2);
                scale        = Mathf.Clamp01(scale);
                value        = new PosAndForce(transform.position, transform.forward * scale);
                value.Force *= LerpAxis(reversePower, power, controlInfo.ForwardAxis);
                return(true);
            }
        }