Example #1
0
        /// <summary>
        /// Apply the position inputs, respecting if the moved gameobject is a rigidbody or not. Moves non-kinematic rigidbodies with force,
        /// moves all others with translation. restrictToNstRanges=true will clamp the ranges to the NST and NST Element ranges set for that object,
        /// if any exist.
        /// </summary>
        /// <param name="moves"></param>
        private void ApplyPosition(Vector3 moves)
        {
            // Position
            // Non kinematic rigidbodies can't really be ranged (without an insane amount of code) and this will be the root object in all cases (rbs can't be on children)
            if (moveWithForce)
            {
                rb.AddRelativeForce(moves * moveForce);
            }
            else
            {
                Vector3 unclamped = _gameObject.transform.localPosition + _gameObject.transform.rotation * moves * moveRate;
                Vector3 clamped   =
                    (restrictToNstRange && pe != null) ? pe.ClampAxes(unclamped) :
                    (restrictToNstRange && isRootGO) ? WorldVectorCompression.ClampAxes(unclamped) : unclamped;

                if (!isRootGO && pe != null)
                {
                    pe.Apply(clamped);
                }
                // If this is the root object, we will want to move this
                else if (rb == null || translateKinematic)
                {
                    _gameObject.transform.localPosition = clamped;
                }
                else
                {
                    rb.MovePosition(clamped);
                }
            }
        }
        /// <summary>
        /// Apply the position inputs, respecting if the moved gameobject is a rigidbody or not. Moves non-kinematic rigidbodies with force,
        /// moves all others with translation. restrictToNstRanges=true will clamp the ranges to the NST and NST Element ranges set for that object,
        /// if any exist.
        /// </summary>
        /// <param name="moves"></param>
        private void ApplyPosition(Vector3 moves)
        {
            bool local = (pe == null || (pe as TransformElement).crusher.local);

            // Position
            // Non kinematic rigidbodies can't really be ranged (without an insane amount of code) and this will be the root object in all cases (rbs can't be on children)
            if (moveWithForce)
            {
                rb.AddRelativeForce(moves * moveForce);
            }
            else
            {
                // TODO: this use of rotation seems very wrong

                Vector3 unclamped =
                    (isRootGO || !local) ?
                    _gameObject.transform.position + _gameObject.transform.rotation * (moves * moveRate) :
                    _gameObject.transform.localPosition + moves * moveRate;

                Vector3 clamped =
                    (restrictToNstRange && pe != null) ? pe.GetCorrectedForOutOfBounds(unclamped) :
                    (restrictToNstRange && isRootGO) ? WorldVectorCompression.ClampAxes(unclamped) : unclamped;

                if (!isRootGO && pe != null)
                {
                    pe.Apply(clamped);
                }
                // If this is the root object, we will want to move this
                else if (rb == null || translateKinematic)
                {
                    if (local)
                    {
                        _gameObject.transform.localPosition = clamped;
                    }
                    else
                    {
                        _gameObject.transform.position = clamped;
                    }
                }

                else
                {
                    rb.MovePosition(clamped);
                }
            }
        }