Exemplo n.º 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);
                }
            }
        }