Beispiel #1
0
        protected virtual void OnMoveStart()
        {
            BaseAStarMgr.GlobalMoveState.Add();
            StateMachine.CurStateData?.OnMoveStart();

            ClearNode();
            ClearBlock();

            GrabNewQuateration();
            Callback_OnMoveStart?.Invoke();
            if (UseFollowCoroutine)
            {
                BattleCoroutine.Kill(FollowPathCoroutine);
                FollowPathCoroutine = BattleCoroutine.Run(OnFollowPathCoroutine());
            }
        }
Beispiel #2
0
        IEnumerator <float> MoveAlongPath(BaseUnit unit, ABPath path, float speed)
        {
            if (path.error || path.vectorPath.Count == 0)
            {
                throw new ArgumentException("Cannot follow an empty path");
            }

            PreMoveUnit = unit;
            Callback_OnMoveStart?.Invoke(unit);

            // Very simple movement, just interpolate using a catmull rom spline
            float distanceAlongSegment = 0;

            for (int i = 0; i < path.vectorPath.Count - 1; i++)
            {
                var p0 = path.vectorPath[Mathf.Max(i - 1, 0)];
                // Start of current segment
                var p1 = path.vectorPath[i];
                // End of current segment
                var p2 = path.vectorPath[i + 1];
                var p3 = path.vectorPath[Mathf.Min(i + 2, path.vectorPath.Count - 1)];

                var segmentLength = Vector3.Distance(p1, p2);

                while (distanceAlongSegment < segmentLength)
                {
                    var interpolatedPoint = MathUtil.CatmullRom(p0, p1, p2, p3, distanceAlongSegment / segmentLength);

                    var targetRot = Quaternion.LookRotation((p2 - p1).SetY(0), Vector3.up);
                    unit.Rot = Quaternion.Slerp(unit.Rot, targetRot, Time.deltaTime * 10);

                    unit.transform.position = interpolatedPoint;

                    Callback_OnMovingAlone?.Invoke(unit, p0, p1, p2, p3);
                    yield return(Timing.WaitForOneFrame);

                    distanceAlongSegment += Time.deltaTime * speed;
                }

                distanceAlongSegment -= segmentLength;
            }

            Vector3 target = path.vectorPath[path.vectorPath.Count - 1];

            unit.Pos = target;
            Callback_OnMoveEnd?.Invoke(unit);
        }
Beispiel #3
0
 protected virtual void OnMoveStart()
 {
     Callback_OnMoveStart?.Invoke();
 }