Пример #1
0
 void IBattleCharacter.StopMove()
 {
     CurrentPath = null;
     if (syncIndex > 0)
     {
         var notify = new Proto.Notify_CharacterPosition()
         {
             LastPosition   = this.transform.position.ToV3(),
             TargetPosition = this.transform.position.ToV3(),
             Index          = this.Index
         };
         PerceptionView.AddNotify(notify);
     }
     syncIndex = 0;
 }
Пример #2
0
        //...
        void UpdatePath(GTime time)
        {
            isMoving = false;
            if (nextWaypoint > finalWaypoint)
            {
                CurrentPath = null;
                return;
            }
            if (nextWaypoint > finalWaypoint)
            {
                return;
            }

            if (this.syncIndex != nextWaypoint)
            {
                this.syncIndex = nextWaypoint;
                var notify = new Proto.Notify_CharacterPosition
                {
                    LastPosition   = this.transform.position.ToV3(),
                    TargetPosition = CurrentPath[nextWaypoint].ToV3(),
                    Index          = this.Index
                };
                this.PerceptionView.AddNotify(notify);
            }

            isMoving = true;
            var fullPath = CurrentPath[nextWaypoint] - CurrentPath[lastWaypoint]; //defines the path between lastWaypoint and nextWaypoint as a Vector3

            faction_of_path_traveled += speed * time.DeltaTime;                   //animate along the path
            if (faction_of_path_traveled > fullPath.magnitude)                    //move to next waypoint
            {
                lastWaypoint++; nextWaypoint++;
                faction_of_path_traveled = 0;
                UpdatePath(time);
                return;
            }
            //we COULD use Translate at this point, but it's simpler to just compute the current position
            var pos = (fullPath.normalized * faction_of_path_traveled) + CurrentPath[lastWaypoint];

            transform.position = pos;
        }