Ejemplo n.º 1
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.º 2
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);
            }
        }
Ejemplo n.º 3
0
 public void AddForce(PosAndForce force)
 {
     _rigidbody.AddForceAtPosition(force.Force, force.Position, ForceMode.Force);
 }