public override void UpdateState() { //Debug.DrawLine(m_stalker.transform.position, m_activePoints.m_currentWaypoint, Color.magenta); if (m_stalkerMotor.TargetReached) { if (m_path.status != NavMeshPathStatus.PathInvalid && m_currentPathIndex < m_path.corners.Length) { m_stalkerMotor.SetNewTarget(m_path.corners[m_currentPathIndex++]); } else { // clear the current path m_path.ClearCorners(); m_currentPathIndex = 0; // Find the next waypoint and find a path to it switch (m_stalkerMotor.CurrentSearchType) { case Motor_Stalker.SearchType.LINEAR: m_stalkerAgent.CalculatePath(Navigation.FindNearestWaypoint(ref m_activePoints), m_path); break; case Motor_Stalker.SearchType.RANDOM: m_stalkerAgent.CalculatePath(Navigation.FindRandomWaypoint(ref m_activePoints), m_path); break; } } } // Move to next position m_stalkerMotor.UpdateMotor(); // Check for player if in range if (m_stalkerMotor.ShouldCheckForNearbyObjects) { // Update the sight m_stalkerMotor.UpdateLOS(); if (m_stalkerMotor.CanSeePlayer) { // Enter pursuit state and set the player's location as the new target m_stalker.SetPursuitState(GameManager.Player.transform); } } }
public override void UpdateState() { // Draw the path in the editor window for (int i = 0; i < m_path.corners.Length - 1; ++i) { Debug.DrawLine(m_path.corners[i], m_path.corners[i + 1], Color.red); } // Update the LOS m_stalkerMotor.UpdateLOS(); // Update the position if the player is still in sight and has moved if (m_stalkerMotor.CanSeePlayer) { if (Vector3.Distance(m_stalker.transform.position, m_target.position) < m_stalkerMotor.AttackRange) { m_stalkerMotor.SetAttacking(true); return; } else { m_stalkerMotor.SetAttacking(false); } if (m_target.position != m_goalPosition) { UpdateGoalPositionAndPath(m_target.position); m_stalkerMotor.SetNewTarget(m_path.corners[0]); } } else if (m_stalkerMotor.TargetReached) { // Continue Along path until goal is reached if (m_path.status != NavMeshPathStatus.PathInvalid && m_currentPathIndex < m_path.corners.Length) { m_stalkerMotor.SetNewTarget(m_path.corners[m_currentPathIndex++]); } else { m_stalker.SetWanderState(); } } m_stalkerMotor.UpdateMotor(); }