Beispiel #1
0
        protected override FSM.State _DoTick(float deltaTime)
        {
            TransformObject target = _Content.FollowTarget;

            if (target == null)
            {
                return(new StayState(_Content));
            }

            if (_Content.FollowRelativeTargetPosition)
            {
                UnityEngine.Quaternion followRelativeRotation = _Content.FollowRelativeRotation * _Content.RelativeTargetRotation;
                if (_Content.FollowRelativeTargetRotation)
                {
                    var targetPos = target.GetPosition() + target.GetRotation() * _Content.FollowRelativePosition;
                    var dir       = target.GetRotation() * followRelativeRotation * UnityEngine.Vector3.back;
                    _Content.TranslateTo(targetPos + dir * _Content.FollowDistance, _Content.FollowSmoothTime);
                    _Content.RotateTo(target.GetRotation() * followRelativeRotation, _Content.FollowSmoothTime);
                }
                else
                {
                    var targetPos = target.GetPosition() + followRelativeRotation * _Content.FollowRelativePosition;
                    var dir       = followRelativeRotation * UnityEngine.Vector3.back;
                    _Content.TranslateTo(targetPos + dir * _Content.FollowDistance, _Content.FollowSmoothTime);
                    _Content.RotateTo(followRelativeRotation, _Content.FollowSmoothTime);
                }
            }
            else
            {
                var dir = target.GetPosition() - _Content.GetPosition();
                if (_Content.FollowRelativeTargetRotation)
                {
                    dir += target.GetRotation() * _Content.FollowRelativePosition;
                }
                else
                {
                    dir += _Content.FollowRelativePosition;
                }
                var right = UnityEngine.Vector3.Cross(UnityEngine.Vector3.up, dir);
                var up    = UnityEngine.Vector3.Cross(dir, right);
                dir.Normalize();
                up.Normalize();
                _Content.RotateTo(dir, up, _Content.FollowSmoothTime);
            }

            return(this);
        }
Beispiel #2
0
        protected override FSM.State _DoTick(float deltaTime)
        {
            TransformObject target = _Content.FollowTarget;

            if (target == null)
            {
                return(new StayState(_Content));
            }

            _TryInit();

            var targetPos = target.GetPosition();

            targetPos.z = 0;
            targetPos  += _Content.FollowRelativePosition + _Content.FollowRelativeRotation * UnityEngine.Vector3.back * _Content.FollowDistance;
            _Content.TranslateTo(targetPos, _Content.FollowSmoothTime);

            return(this);
        }