Example #1
0
        protected override void HandleFrameUpdate(float elapsedTime)
        {
            base.HandleFrameUpdate(elapsedTime);

            Collider playerCollider = null;

            if (IsWithinPlayerProximity(ref playerCollider, controller.playerProximityRadius))
            {
                // close to the player.  Move to the attack state
            }
            else
            {
                // Move to the player
                controller.Agent.destination = followTarget.position;
            }

            if (!IsPlayerVisible())
            {
                // Move to the last know position
                if (controller.LastSighting.HasSighting())
                {
                    var moveToLastKnown = new AIStateMoveToLastKnownPosition(controller);
                    stateMachine.MoveTo(moveToLastKnown);
                }
                else
                {
                    // We don't have a last know position. Resume patroling
                    var patrol = new AIStatePatrol(controller);
                    stateMachine.MoveTo(patrol);
                }
                return;
            }
            else
            {
                // Player is visible.  Update the last sighting
                controller.LastSighting.Position = followTarget.position;
            }
        }
		protected override void HandleFrameUpdate (float elapsedTime)
		{
			base.HandleFrameUpdate(elapsedTime);

			Collider playerCollider = null;
			if (IsWithinPlayerProximity(ref playerCollider, controller.playerProximityRadius)) {
				// close to the player.  Move to the attack state
			} else {
				// Move to the player
				controller.Agent.Destination = followTarget.position;
			}

			if (!IsPlayerVisible()) {
				// Move to the last know position
				if (controller.LastSighting.HasSighting()) {
					var moveToLastKnown = new AIStateMoveToLastKnownPosition(controller);
					stateMachine.MoveTo(moveToLastKnown);
				} else {
					// We don't have a last know position. Resume patroling 
					var patrol = new AIStatePatrol(controller);
					stateMachine.MoveTo(patrol);
				}
				return;
			} else {
				// Player is visible.  Update the last sighting
				controller.LastSighting.Position = followTarget.position;
			}
		}