protected virtual void LateUpdate()
        {
            // Cache
            var finalTransform = FinalTransform;

            // Update position and delta
            var currentPosition = finalTransform.position;

            if (Position == PositionType.PreviousPosition && Vector3.Distance(previousPosition, currentPosition) > Threshold)
            {
                SetDelta(currentPosition - previousPosition);

                previousPosition = currentPosition;
            }

            // Update rotation
            var currentRotation = finalTransform.localRotation;
            var factor          = LeanHelper.GetDampenFactor(Damping, Time.deltaTime);

            if (previousDelta.sqrMagnitude > 0.0f)
            {
                UpdateRotation(finalTransform, previousDelta);
            }

            finalTransform.localRotation = Quaternion.Slerp(currentRotation, finalTransform.localRotation, factor);
        }
Ejemplo n.º 2
0
        protected virtual void UpdatePosition(float damping, float linear)
        {
            if (positionSet == true || Continuous == true)
            {
                if (destination != null)
                {
                    Position = destination.TransformPoint(DestinationOffset);
                }

                var currentPosition = transform.position;
                var targetPosition  = Position + Offset;

                if (IgnoreZ == true)
                {
                    targetPosition.z = currentPosition.z;
                }

                // Get t value
                var factor = LeanHelper.GetDampenFactor(damping, Time.deltaTime);

                // Move current value to the target one
                currentPosition = Vector3.Lerp(currentPosition, targetPosition, factor);
                currentPosition = Vector3.MoveTowards(currentPosition, targetPosition, linear * Time.deltaTime);

                // Apply new point
                transform.position = currentPosition;

                positionSet = false;
            }
        }
Ejemplo n.º 3
0
        protected virtual void Update()
        {
            var finalTransform    = Target != null ? Target.transform : transform;
            var factor            = LeanHelper.GetDampenFactor(Damping, Time.deltaTime);
            var newRemainingDelta = Vector3.Lerp(remainingDelta, Vector3.zero, factor);
            var rigidbody         = finalTransform.GetComponent <Rigidbody>();

            if (rigidbody != null)
            {
                if (ResetVelocityInUpdate == true)
                {
                    rigidbody.velocity = Vector3.zero;
                }

                rigidbody.velocity += (remainingDelta - newRemainingDelta) / Time.deltaTime;
            }

            if (controlling == false && Inertia > 0.0f && Damping > 0.0f)
            {
                newRemainingDelta = Vector3.Lerp(newRemainingDelta, remainingDelta, Inertia);
            }

            remainingDelta = newRemainingDelta;
            controlling    = false;
        }
        protected override void UpdatePosition(float damping, float linear)
        {
            if (positionSet == true || Continuous == true)
            {
                if (destination != null)
                {
                    Position = destination.TransformPoint(DestinationOffset);
                }

                var currentPosition = (Vector2)(transform.position);
                var targetPosition  = (Vector2)(Position + Offset);

                var direction = targetPosition - currentPosition;
                var velocity  = direction / Time.fixedDeltaTime;

                // Apply the velocity
                velocity *= LeanHelper.GetDampenFactor(damping, Time.fixedDeltaTime);
                velocity  = Vector3.MoveTowards(velocity, Vector3.zero, linear * Time.fixedDeltaTime);

                if (axis == AxisType.Horizontal)
                {
                    velocity.y = cachedRigidbody.velocity.y;
                }
                else if (axis == AxisType.Vertical)
                {
                    velocity.x = cachedRigidbody.velocity.x;
                }

                cachedRigidbody.velocity = velocity;

                fixedUpdateCalled = true;
            }
        }
Ejemplo n.º 5
0
        protected virtual void LateUpdate()
        {
            var currentPosition = transform.position;
            var newVector       = (Vector2)(currentPosition - previousPosition);

            if (newVector.sqrMagnitude > 0.0f)
            {
                vector = newVector;
            }

            var currentRotation = transform.localRotation;
            var factor          = LeanHelper.GetDampenFactor(Damping, Time.deltaTime);

            if (vector.sqrMagnitude > 0.0f)
            {
                var angle           = Mathf.Atan2(vector.x, vector.y) * Mathf.Rad2Deg;
                var directionB      = (Vector2)transform.up;
                var angleB          = Mathf.Atan2(directionB.x, directionB.y) * Mathf.Rad2Deg;
                var delta           = Mathf.DeltaAngle(angle, angleB);
                var angularVelocity = delta / Time.fixedDeltaTime;

                angularVelocity *= LeanHelper.GetDampenFactor(Damping, Time.fixedDeltaTime);

                cachedRigidbody2D.angularVelocity = angularVelocity;
            }

            transform.localRotation = Quaternion.Slerp(currentRotation, transform.localRotation, factor);

            previousPosition = currentPosition;
        }
        protected virtual void Update()
        {
            if (reverting == true)
            {
                if (ReachedTarget() == true)
                {
                    reverting = false;

                    return;
                }

                // Get t value
                var factor = LeanHelper.GetDampenFactor(Damping, Time.deltaTime);

                if (RevertPosition == true)
                {
                    transform.localPosition = Vector3.Lerp(transform.localPosition, TargetPosition, factor);
                }

                if (RevertRotation == true)
                {
                    transform.localRotation = Quaternion.Slerp(transform.localRotation, TargetRotation, factor);
                }

                if (RevertScale == true)
                {
                    transform.localScale = Vector3.Lerp(transform.localScale, TargetScale, factor);
                }
            }
        }
Ejemplo n.º 7
0
        protected virtual void LateUpdate()
        {
            var worldOrigin    = transform.parent != null ? transform.parent.position : Vector3.zero;
            var worldDirection = Direction;

            // Get a valid normalized direction
            if (worldDirection.sqrMagnitude == 0.0f)
            {
                worldDirection = transform.position - worldOrigin;

                if (worldDirection.sqrMagnitude == 0.0f)
                {
                    worldDirection = Random.onUnitSphere;
                }
            }
            else if (DirectionSpace == Space.Self)
            {
                worldDirection = transform.TransformDirection(worldDirection);
            }

            worldDirection = worldDirection.normalized;

            // Limit distance to min/max values?
            if (Clamp == true)
            {
                Distance = Mathf.Clamp(Distance, ClampMin, ClampMax);
            }

            // Collide against stuff?
            if (CollisionLayers != 0)
            {
                var hit    = default(RaycastHit);
                var pointA = worldOrigin + worldDirection * ClampMin;
                var pointB = worldOrigin + worldDirection * ClampMax;

                if (Physics.SphereCast(pointA, CollisionRadius, worldDirection, out hit, Vector3.Distance(pointA, pointB), CollisionLayers) == true)
                {
                    var newDistance = hit.distance + ClampMin;

                    // Only update if the distance is closer, else the camera can glue to walls behind it
                    if (newDistance < Distance)
                    {
                        Distance = newDistance;
                    }
                }
            }

            // Get t value
            var factor = LeanHelper.GetDampenFactor(Damping, Time.deltaTime);

            // Lerp the current value to the target one
            currentDistance = Mathf.Lerp(currentDistance, Distance, factor);

            // Set the position
            transform.position = worldOrigin + worldDirection * currentDistance;
        }
Ejemplo n.º 8
0
        protected virtual void FixedUpdate()
        {
            var finalTransform = Target != null ? Target.transform : transform;
            var factor         = LeanHelper.GetDampenFactor(Damping, Time.fixedDeltaTime);
            var newDelta       = Vector2.Lerp(remainingDelta, Vector2.zero, factor);
            var rigidbody      = finalTransform.GetComponent <Rigidbody2D>();

            if (rigidbody != null)
            {
                rigidbody.velocity += (remainingDelta - newDelta) / Time.fixedDeltaTime;
            }

            remainingDelta = newDelta;
        }
Ejemplo n.º 9
0
        protected virtual void Update()
        {
            // Get t value
            var factor = LeanHelper.GetDampenFactor(Damping, Time.deltaTime);

            if (Clamp == true)
            {
                Angle = Mathf.Clamp(Angle, ClampMin, ClampMax);
            }

            // Lerp angle
            currentAngle = Mathf.LerpAngle(currentAngle, Angle, factor);

            // Update rotation
            transform.rotation = Quaternion.Euler(0.0f, 0.0f, -currentAngle);
        }
Ejemplo n.º 10
0
        protected virtual void Update()
        {
            if (targetSet == true)
            {
                var factor = LeanHelper.GetDampenFactor(Damping, Time.deltaTime);

                currentValue = Vector3.Lerp(currentValue, targetValue, factor);
                currentValue = Vector3.MoveTowards(currentValue, targetValue, Threshold * Time.deltaTime);

                Submit(currentValue);

                if (AutoStop == true && Vector3.SqrMagnitude(currentValue - targetValue) == 0.0f)
                {
                    Stop();
                }
            }
        }
Ejemplo n.º 11
0
        protected override void UpdatePosition(float damping, float linear)
        {
            if (positionSet == true || Continuous == true)
            {
                if (destination != null)
                {
                    Position = destination.TransformPoint(DestinationOffset);
                }

                var currentPosition = transform.position;
                var targetPosition  = Position + Offset;

                if (IgnoreZ == true)
                {
                    targetPosition.z = currentPosition.z;
                }

                var direction = targetPosition - currentPosition;
                var velocity  = direction / Time.fixedDeltaTime;

                // Apply the velocity
                velocity *= LeanHelper.GetDampenFactor(damping, Time.fixedDeltaTime);
                velocity  = Vector3.MoveTowards(velocity, Vector3.zero, linear * Time.fixedDeltaTime);

                cachedRigidbody.velocity = velocity;
                Debug.Log(velocity);

                /*
                 * if (Rotation == true && direction != Vector3.zero)
                 * {
                 *      var angle           = Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg;
                 *      var directionB      = (Vector2)transform.up;
                 *      var angleB          = Mathf.Atan2(directionB.x, directionB.y) * Mathf.Rad2Deg;
                 *      var delta           = Mathf.DeltaAngle(angle, angleB);
                 *      var angularVelocity = delta / Time.fixedDeltaTime;
                 *
                 *      angularVelocity *= LeanHelper.GetDampenFactor(RotationDamping, Time.fixedDeltaTime);
                 *
                 *      //cachedRigidbody.angularVelocity = angularVelocity;
                 * }
                 */
                fixedUpdateCalled = true;
            }
        }
Ejemplo n.º 12
0
        protected virtual void LateUpdate()
        {
            if (Pivot != null)
            {
                var angles = Quaternion.LookRotation(Pivot.position - transform.position, Vector3.up).eulerAngles;

                Pitch = angles.x;
                Yaw   = angles.y;
            }

            // Get t value
            var factor = LeanHelper.GetDampenFactor(Damping, Time.deltaTime);

            // Lerp the current values to the target ones
            currentPitch = Mathf.Lerp(currentPitch, Pitch, factor);
            currentYaw   = Mathf.Lerp(currentYaw, Yaw, factor);

            // Rotate to pitch and yaw values
            transform.localRotation = Quaternion.Euler(currentPitch, currentYaw, 0.0f);
        }
Ejemplo n.º 13
0
        protected virtual void LateUpdate()
        {
            if (PitchClamp == true)
            {
                Pitch = Mathf.Clamp(Pitch, PitchMin, PitchMax);
            }

            if (YawClamp == true)
            {
                Yaw = Mathf.Clamp(Yaw, YawMin, YawMax);
            }

            // Get t value
            var factor = LeanHelper.GetDampenFactor(Damping, Time.deltaTime);

            // Lerp the current values to the target ones
            currentPitch = Mathf.Lerp(currentPitch, Pitch, factor);
            currentYaw   = Mathf.Lerp(currentYaw, Yaw, factor);

            // Rotate to pitch and yaw values
            transform.localRotation = Quaternion.Euler(currentPitch, currentYaw, 0.0f);
        }
Ejemplo n.º 14
0
        protected virtual void Update()
        {
            var factor = LeanHelper.GetDampenFactor(damping, Time.deltaTime);

            UpdateRotation(factor);
        }