1015 lines
37 KiB
C#
1015 lines
37 KiB
C#
using InfallibleCode;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
using UnityEngine.Playables;
|
|
using UnityStandardAssets.Characters.ThirdPerson;
|
|
|
|
public class MedeaDemonicEnemyBehaviour : MonoBehaviour
|
|
{
|
|
private static MedeaDemonicEnemyBehaviour _instance;
|
|
public static MedeaDemonicEnemyBehaviour GetInstance() { return _instance; }
|
|
|
|
#region Medea & Player useful variables
|
|
public Animator medeaAnimator;
|
|
[SerializeField] public NavMeshAgent _medeaAI;
|
|
[SerializeField] private ThirdPersonCharacter thirdPerson;
|
|
[SerializeField] bool _followPlayer;
|
|
[SerializeField] bool _playerReached;
|
|
[SerializeField] Transform _player;
|
|
[SerializeField] public Transform _medea;
|
|
public List<SkinnedMeshRenderer> _medeaSkinnedMeshRenderer;
|
|
|
|
//[SerializeField] private Animator _MedeaAnimations;
|
|
#endregion
|
|
|
|
#region Alerted or not variables
|
|
[SerializeField] private float _viewRadius;
|
|
[SerializeField] private float _viewAngle;
|
|
|
|
[SerializeField] private float _hearingRadius;
|
|
[SerializeField] private float _hearingAngle;
|
|
|
|
[SerializeField] private float _alertedViewRadius;
|
|
[SerializeField] private float _alertedViewAngle;
|
|
private float _defaultViewRadius;
|
|
private float _defaultViewAngle;
|
|
#endregion
|
|
|
|
public LayerMask playerMask;
|
|
public LayerMask obstacleMask;
|
|
|
|
|
|
[SerializeField] private float _movementSpeed = 5f;
|
|
private float _defaultMovementSpeed = 20;
|
|
[SerializeField] private float _currentRotSpeed;
|
|
private float _defaulfRotSpeed = 120;
|
|
|
|
private float _defaultMovingTurnSpeed;
|
|
private float _defaultStationaryTurnSpeed;
|
|
|
|
[SerializeField] private Transform _closet;
|
|
[SerializeField] private Transform _bed;
|
|
|
|
public ClosetHideBehaviour closetHideBehaviour;
|
|
|
|
#region Timers
|
|
|
|
//private Coroutine _medeaDespawnTimer;
|
|
|
|
#endregion
|
|
|
|
#region Audio
|
|
private AudioSource _MedeaDangerAudioSource;
|
|
[SerializeField] private AudioClip _DangerAudioClip;
|
|
private bool _playingMusic;
|
|
#endregion
|
|
|
|
private Coroutine _playerLostContinueChasingTimer;
|
|
bool hasLostPlayer;
|
|
|
|
bool medeaMeshRenderersAreDisabled;
|
|
|
|
public enum medeaState
|
|
{
|
|
Default,
|
|
Spawn,
|
|
ChasePlayer,
|
|
Patroling,
|
|
SearchingForHiddenPlayer,
|
|
TakingOutPlayerFromHiddingSpot,
|
|
KillingPlayer,
|
|
Disabled,
|
|
TrafficPuzzle,
|
|
OrangeLights
|
|
}
|
|
|
|
public medeaState state = medeaState.Spawn;
|
|
|
|
private void Awake()
|
|
{
|
|
if (!_instance)
|
|
{
|
|
_instance = this;
|
|
}
|
|
|
|
_MedeaDangerAudioSource = GetComponent<AudioSource>();
|
|
|
|
_defaultViewAngle = _viewAngle;
|
|
_defaultViewRadius = _viewRadius;
|
|
|
|
_medeaAI.angularSpeed = _defaulfRotSpeed;
|
|
_currentRotSpeed = _defaulfRotSpeed;
|
|
|
|
_defaultStationaryTurnSpeed = thirdPerson.m_StationaryTurnSpeed;
|
|
_defaultMovingTurnSpeed = thirdPerson.m_MovingTurnSpeed;
|
|
|
|
|
|
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
_medeaAI.updateRotation = false;
|
|
_medeaAI = GetComponent<NavMeshAgent>();
|
|
_player = PlayerManager.GetInstance().playerGameObj.transform;
|
|
_defaultMovementSpeed = _medeaAI.speed;
|
|
}
|
|
|
|
#region Audio
|
|
public void PlayDangerMusic()
|
|
{
|
|
if (_playingMusic)
|
|
{
|
|
_MedeaDangerAudioSource.clip = _DangerAudioClip;
|
|
_MedeaDangerAudioSource.Play();
|
|
_playingMusic = false;
|
|
}
|
|
if (_MedeaDangerAudioSource.isPlaying == false)
|
|
{
|
|
_playingMusic = true;
|
|
}
|
|
}
|
|
public void StopDangerMusic()
|
|
{
|
|
_MedeaDangerAudioSource.Stop();
|
|
_MedeaDangerAudioSource.clip = null;
|
|
_playingMusic = false;
|
|
}
|
|
#endregion
|
|
|
|
#region Call States
|
|
public void GoToDefaultMedeaState()
|
|
{
|
|
state = medeaState.Default;
|
|
}
|
|
|
|
public void GoToSpawnMedeaState()
|
|
{
|
|
state = medeaState.Spawn;
|
|
}
|
|
|
|
public void GoToTrafficPuzzleState()
|
|
{
|
|
state = medeaState.TrafficPuzzle;
|
|
}
|
|
|
|
public void GoToChasePlayerState()
|
|
{
|
|
state = medeaState.ChasePlayer;
|
|
}
|
|
|
|
public void GoToDisabledMedeaState()
|
|
{
|
|
state = medeaState.Disabled;
|
|
}
|
|
|
|
public void TrafficLightPuzzleSolved()
|
|
{
|
|
_medeaAI.speed = _defaultMovementSpeed;
|
|
medeaAnimator.SetBool("IsWalkingBackwards", false);
|
|
state = medeaState.Disabled;
|
|
}
|
|
#endregion
|
|
|
|
public void MedeaIsStopped()
|
|
{
|
|
_medeaAI.isStopped = true;
|
|
}
|
|
|
|
public void MedeaIsNoLongerStopped()
|
|
{
|
|
_medeaAI.isStopped = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// If was chasing player and player is lost from the field of view.
|
|
/// </summary>
|
|
public void StartPlayerLostContinueChasingTimer()
|
|
{
|
|
if (!hasLostPlayer)
|
|
{
|
|
if (!IsPlayerHidden()) //12.8.24
|
|
{
|
|
_playerLostContinueChasingTimer = StartCoroutine(PlayerLostContinueChasingTimer()); //that was here 12.8.24
|
|
}
|
|
else //12.8.24
|
|
{
|
|
StopAllCoroutines();
|
|
}
|
|
//_medeaAI.SetDestination(_player.transform.localPosition); //16.7.24
|
|
|
|
}
|
|
}
|
|
|
|
IEnumerator PlayerLostContinueChasingTimer()
|
|
{
|
|
hasLostPlayer = true;
|
|
StartCoroutine(UpdatePlayerPositionForMedeaWhilePlayerIsLost());
|
|
print("Update player destination while medea lot player");
|
|
yield return new WaitForSeconds(20f);
|
|
print("Ten seconds since enemy lost player has passed");
|
|
//if (state != medeaState.SearchingForHiddenPlayer || state != medeaState.TakingOutPlayerFromHiddingSpot)
|
|
//{
|
|
// print("Was not in searching for hidden player");
|
|
// PatrolManager.GetInstance()._canChangePoint = true; //13.8.24
|
|
// state = medeaState.Patroling;
|
|
//}
|
|
//else
|
|
//{
|
|
// state = medeaState.Spawn;
|
|
// print("20 seconds since enemy lost the player and now the enemy is searching");
|
|
//}
|
|
//hasLostPlayer = false;
|
|
SecondsPassedSinceEnemyLostPlayer();
|
|
}
|
|
|
|
public void StopPlayerLostContinueChasingTimer()
|
|
{
|
|
if (_playerLostContinueChasingTimer != null)
|
|
{
|
|
StopCoroutine(_playerLostContinueChasingTimer);
|
|
_playerLostContinueChasingTimer = null;
|
|
SecondsPassedSinceEnemyLostPlayer();
|
|
print("Stopped PlayerLostContinuechasing timer");
|
|
}
|
|
}
|
|
|
|
public void SecondsPassedSinceEnemyLostPlayer()
|
|
{
|
|
print("Ten seconds since enemy lost player has passed");
|
|
if (state != medeaState.SearchingForHiddenPlayer || state != medeaState.TakingOutPlayerFromHiddingSpot)
|
|
{
|
|
print("Was not in searching for hidden player");
|
|
PatrolManager.GetInstance()._canChangePoint = true; //13.8.24
|
|
state = medeaState.Patroling;
|
|
}
|
|
else
|
|
{
|
|
state = medeaState.Spawn;
|
|
print("20 seconds since enemy lost the player and now the enemy is searching");
|
|
}
|
|
hasLostPlayer = false;
|
|
}
|
|
|
|
IEnumerator UpdatePlayerPositionForMedeaWhilePlayerIsLost()
|
|
{
|
|
while (hasLostPlayer)
|
|
{
|
|
_medeaAI.SetDestination(_player.transform.localPosition); //16.7.24
|
|
print("Is updating player destination while player is out of sight from Medea");
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
// FindPlayer();
|
|
if (PlayerDeath.GetInstance().playerIsDead == false)
|
|
{
|
|
//If agent has not reached the desired destination :
|
|
UpdateEnemyMovement();
|
|
|
|
if (CanSeePlayer() || CanHearPlayer()/*&& !PlayerDeath.GetInstance().playerIsDead*/)
|
|
{
|
|
PlayDangerMusic();
|
|
}
|
|
else
|
|
{
|
|
StopDangerMusic();
|
|
}
|
|
|
|
}
|
|
UpdateEnemyBehaviour();
|
|
}
|
|
|
|
void UpdateEnemyBehaviour()
|
|
{
|
|
#region Medea's animations handling
|
|
float speed = _medeaAI.velocity.magnitude;
|
|
// Map NavMeshAgent's speed to blend tree parameter
|
|
float normalizedSpeed = speed / _medeaAI.speed; // Adjust the divisor to match your maximum NavMeshAgent speed
|
|
medeaAnimator.SetFloat("speedPercent", normalizedSpeed);
|
|
#endregion
|
|
|
|
switch (state)
|
|
{
|
|
case medeaState.Default:
|
|
// PatrolManager.GetInstance().CanPatrol = true;
|
|
//Check player state
|
|
|
|
if (medeaMeshRenderersAreDisabled)
|
|
{
|
|
|
|
EnableMedeaMeshRenderers();
|
|
_medeaAI.isStopped = false;
|
|
}
|
|
break;
|
|
case medeaState.Spawn:
|
|
// PatrolManager.GetInstance().CanPatrol = true;
|
|
//Check player state
|
|
_medeaAI.speed = _defaultMovementSpeed;
|
|
|
|
_currentRotSpeed = _defaulfRotSpeed;
|
|
_medeaAI.angularSpeed = _defaulfRotSpeed;
|
|
|
|
thirdPerson.m_StationaryTurnSpeed = _defaultStationaryTurnSpeed ;
|
|
thirdPerson.m_MovingTurnSpeed = _defaultMovingTurnSpeed;
|
|
|
|
//
|
|
if (!_medeaAI.isActiveAndEnabled)
|
|
{
|
|
this.gameObject.SetActive(true);
|
|
PatrolManager.GetInstance()._canChangePoint = false; //tocheck this
|
|
EnableMedeaMeshRenderers();
|
|
_medeaAI.isStopped = false;
|
|
if (CanHearPlayer() || CanSeePlayer())
|
|
{
|
|
state = medeaState.ChasePlayer;
|
|
}
|
|
else if(!IsPlayerHidden())
|
|
{
|
|
PatrolManager.GetInstance().content = PatrolManager.Rute.LostPlayerPath;
|
|
state = medeaState.Patroling;
|
|
}
|
|
else
|
|
{
|
|
PatrolManager.GetInstance().content = PatrolManager.Rute.LostPlayerPath;
|
|
state = medeaState.SearchingForHiddenPlayer;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (CanHearPlayer() || CanSeePlayer())
|
|
{
|
|
PatrolManager.GetInstance()._canChangePoint = false; //13.08.2024
|
|
state = medeaState.ChasePlayer;
|
|
}
|
|
else if (!IsPlayerHidden())
|
|
{
|
|
PatrolManager.GetInstance()._canChangePoint = true; //13.08.2024
|
|
state = medeaState.Patroling;
|
|
}
|
|
else
|
|
{
|
|
PatrolManager.GetInstance()._canChangePoint = true; //13.08.2024
|
|
state = medeaState.SearchingForHiddenPlayer;
|
|
}
|
|
}
|
|
|
|
break;
|
|
|
|
case medeaState.ChasePlayer:
|
|
|
|
if (CanSeePlayer())
|
|
{
|
|
PatrolManager.GetInstance().CanPatrol = false;
|
|
_medeaAI.SetDestination(_player.position);
|
|
IsAlerted();
|
|
if (Vector3.Distance(_player.position, _medea.position) <= 0.5)
|
|
{
|
|
state = medeaState.KillingPlayer;
|
|
}
|
|
|
|
if (IsPlayerHidden())
|
|
{
|
|
Debug.Log("Kriftike eno ton kinigouse");
|
|
//Updates the spot for the enemy to go to:
|
|
PatrolManager.GetInstance().SetNearbyRoomsPatrolPoints();
|
|
PatrolManager.GetInstance().UpdateTakeOutPlayerSpot();
|
|
//Goes to the spot:
|
|
PatrolManager.GetInstance().content = PatrolManager.Rute.GoesToTakeOutPlayerFromHiddingSpotPath;
|
|
state = medeaState.TakingOutPlayerFromHiddingSpot;
|
|
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Einai mprosta tis kai ton vlepei");
|
|
//state = medeaState.ChasePlayer;
|
|
|
|
}
|
|
|
|
}
|
|
else if (!CanSeePlayer())
|
|
{
|
|
IsAlerted();
|
|
//PatrolManager.GetInstance().CanPatrol = true;
|
|
if (IsPlayerHidden())
|
|
{
|
|
Debug.Log("Kriftike kai den ton eide");
|
|
PatrolManager.GetInstance().SetNearbyRoomsPatrolPoints();
|
|
PatrolManager.GetInstance().UpdatePatrolHidingSpots();
|
|
PatrolManager.GetInstance()._destinationPoint = 0;
|
|
PatrolManager.GetInstance().content = PatrolManager.Rute.SearchingForHiddenPlayerPath;
|
|
state = medeaState.SearchingForHiddenPlayer;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Den ton vlepei kai den einai krimenos");
|
|
StartPlayerLostContinueChasingTimer();
|
|
//state = medeaState.Patroling;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case medeaState.Patroling:
|
|
|
|
StopAllCoroutines();
|
|
if (!IsPlayerHidden())
|
|
{
|
|
if (CanSeePlayer())
|
|
{
|
|
//Yiannis added: 19/02/2023
|
|
_medeaAI.isStopped = false;
|
|
PatrolManager.GetInstance()._canChangePoint = true;
|
|
//---------------------------------------------------
|
|
|
|
PatrolManager.GetInstance().CanPatrol = false;
|
|
IsAlerted();
|
|
if (IsPlayerHidden())
|
|
{
|
|
Debug.Log("Kriftike eno ton kinigouse");
|
|
//Updates the spot for the enemy to go to:
|
|
PatrolManager.GetInstance().SetNearbyRoomsPatrolPoints();
|
|
PatrolManager.GetInstance().UpdateTakeOutPlayerSpot();
|
|
//Goes to the spot:
|
|
PatrolManager.GetInstance().content = PatrolManager.Rute.GoesToTakeOutPlayerFromHiddingSpotPath;
|
|
state = medeaState.TakingOutPlayerFromHiddingSpot;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Einai mprosta tis kai ton vlepei");
|
|
StopSearchingAnimation();
|
|
state = medeaState.ChasePlayer;
|
|
|
|
}
|
|
|
|
}
|
|
//I commented out:
|
|
else if (!CanSeePlayer())
|
|
{
|
|
IsAlerted();
|
|
//PatrolManager.GetInstance().CanPatrol = false;
|
|
if (IsPlayerHidden())
|
|
{
|
|
Debug.Log("Kriftike kai den ton eide");
|
|
PatrolManager.GetInstance().SetNearbyRoomsPatrolPoints();
|
|
PatrolManager.GetInstance().UpdatePatrolHidingSpots();
|
|
PatrolManager.GetInstance()._destinationPoint = 0;
|
|
PatrolManager.GetInstance().content = PatrolManager.Rute.SearchingForHiddenPlayerPath;
|
|
PatrolManager.GetInstance().CanPatrol = true; // 10.8.24
|
|
state = medeaState.SearchingForHiddenPlayer;
|
|
}
|
|
else
|
|
{
|
|
//PatrolManager.GetInstance().CanPatrol = true;
|
|
Debug.Log("Den ton vlepei kai den einai krimenos");
|
|
//StartPlayerLostContinueChasingTimer(); //Added 12.7.24
|
|
PatrolManager.GetInstance().content = PatrolManager.Rute.DefinedPath;
|
|
state = medeaState.Patroling;
|
|
}
|
|
}
|
|
|
|
if (CanHearPlayer())
|
|
{
|
|
PatrolManager.GetInstance().CanPatrol = false;
|
|
_medeaAI.SetDestination(_player.position);
|
|
IsAlerted();
|
|
Debug.Log("TON AKOUO TON MALAKA");
|
|
StopSearchingAnimation();
|
|
state = medeaState.ChasePlayer;
|
|
}
|
|
}
|
|
|
|
break;
|
|
|
|
case medeaState.SearchingForHiddenPlayer:
|
|
//IsAlerted();
|
|
PatrolManager.GetInstance().CanPatrol = true;
|
|
//Take the hidden spots of the room the player is in
|
|
//See the closest to the player
|
|
//Dont search there
|
|
|
|
//Dont forget that is medea sees the player she is chasing
|
|
|
|
//If player is not hiding anymore THEN CanSeePlayer.
|
|
if (!IsPlayerHidden())
|
|
{
|
|
if (CanSeePlayer())
|
|
{
|
|
PatrolManager.GetInstance().CanPatrol = false;
|
|
IsAlerted();
|
|
if (IsPlayerHidden())
|
|
{
|
|
Debug.Log("Kriftike eno ton kinigouse");
|
|
//Updates the spot for the enemy to go to:
|
|
PatrolManager.GetInstance().SetNearbyRoomsPatrolPoints();
|
|
PatrolManager.GetInstance().UpdateTakeOutPlayerSpot();
|
|
//Goes to the spot:
|
|
PatrolManager.GetInstance().content = PatrolManager.Rute.GoesToTakeOutPlayerFromHiddingSpotPath;
|
|
state = medeaState.TakingOutPlayerFromHiddingSpot;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Einai mprosta tis kai ton vlepei");
|
|
StopSearchingAnimation();
|
|
state = medeaState.ChasePlayer;
|
|
|
|
}
|
|
|
|
}
|
|
else if (!CanSeePlayer())
|
|
{
|
|
IsAlerted();
|
|
PatrolManager.GetInstance().CanPatrol = false;
|
|
if (IsPlayerHidden())
|
|
{
|
|
Debug.Log("Kriftike kai den ton eide");
|
|
PatrolManager.GetInstance().SetNearbyRoomsPatrolPoints();
|
|
PatrolManager.GetInstance().UpdatePatrolHidingSpots();
|
|
PatrolManager.GetInstance()._destinationPoint = 0;
|
|
PatrolManager.GetInstance().content = PatrolManager.Rute.SearchingForHiddenPlayerPath;
|
|
state = medeaState.SearchingForHiddenPlayer; // 10.8.24 I commented in(Maya)
|
|
}
|
|
else
|
|
{
|
|
PatrolManager.GetInstance().CanPatrol = true;
|
|
Debug.Log("Den ton vlepei kai den einai krimenos");
|
|
PatrolManager.GetInstance().content = PatrolManager.Rute.DefinedPath;
|
|
//state = medeaState.Patroling; //commented out 12.7.24
|
|
StartPlayerLostContinueChasingTimer(); // added 12.7.24
|
|
|
|
}
|
|
}
|
|
|
|
if (CanHearPlayer())
|
|
{
|
|
PatrolManager.GetInstance().CanPatrol = false;
|
|
_medeaAI.SetDestination(_player.position);
|
|
IsAlerted();
|
|
StopSearchingAnimation();
|
|
state = medeaState.ChasePlayer;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!CanSeePlayer())
|
|
{
|
|
//14.08.24
|
|
Debug.Log("Kriftike eno ton kinigouse");
|
|
//Updates the spot for the enemy to go to:
|
|
PatrolManager.GetInstance().SetNearbyRoomsPatrolPoints();
|
|
PatrolManager.GetInstance().UpdateTakeOutPlayerSpot();
|
|
//Goes to the spot:
|
|
PatrolManager.GetInstance().content = PatrolManager.Rute.SearchingForHiddenPlayerPath;
|
|
//state = medeaState.TakingOutPlayerFromHiddingSpot;
|
|
}
|
|
|
|
}
|
|
//StopAllCoroutines();
|
|
|
|
break;
|
|
|
|
case medeaState.TakingOutPlayerFromHiddingSpot:
|
|
|
|
//Take the hidden spots of the room the player is in
|
|
//see the closest to the player
|
|
//Go there and play the animation
|
|
//Dont forget that if medea sees the player she is chasing
|
|
|
|
////If can see player:
|
|
//if (CanSeePlayer())
|
|
//{
|
|
IsAlerted();
|
|
if (!IsPlayerHidden()) //If player is not hidden anymore:
|
|
{
|
|
PatrolManager.GetInstance().CanPatrol = false;
|
|
PatrolManager.GetInstance()._canChangePoint = true;
|
|
Debug.Log("Einai mprosta tis kai ton vlepei");
|
|
PatrolManager.GetInstance().content = PatrolManager.Rute.LostPlayerPath;
|
|
_medeaAI.destination = _player.position;
|
|
state = medeaState.ChasePlayer;
|
|
}
|
|
else
|
|
{
|
|
PatrolManager.GetInstance().isPatroling();
|
|
}
|
|
#region OLD
|
|
//}
|
|
//else //If cant see:
|
|
//{
|
|
// IsAlerted();
|
|
// //PatrolManager.GetInstance().CanPatrol = true;
|
|
// if (!IsPlayerHidden()) //If player is not hidden anymore:
|
|
// {
|
|
// //Even if the enemy can't see the player (Because for example he goes behind a wall) we still need to force the Enemy to go to his direction.
|
|
// PatrolManager.GetInstance().CanPatrol = false;
|
|
// PatrolManager.GetInstance()._canChangePoint = true;
|
|
// Debug.Log("The player is lost from Medeas gaze");
|
|
// PatrolManager.GetInstance().content = PatrolManager.Rute.LostPlayerPath;
|
|
// state = medeaState.ChasePlayer;
|
|
// }
|
|
//}
|
|
#endregion
|
|
break;
|
|
|
|
case medeaState.KillingPlayer:
|
|
_medeaAI.enabled = false;
|
|
//_medea.gameObject.GetComponent<MeshRenderer>().enabled = false;
|
|
DisableMedeaMeshRenderers();
|
|
PlayerDeath.GetInstance().LowSanityGhostKillsPlayer();
|
|
Debug.Log("I killed him");
|
|
|
|
break;
|
|
|
|
case medeaState.Disabled:
|
|
|
|
_medeaAI.isStopped = true;
|
|
_medeaAI.ResetPath(); //this clears the current path
|
|
PatrolManager.GetInstance()._canChangePoint = false;//
|
|
medeaAnimator.SetBool("IsLookingAround", false);
|
|
medeaAnimator.StopPlayback();
|
|
StopAllCoroutines();
|
|
DisableMedeaMeshRenderers();
|
|
this.gameObject.SetActive(false);
|
|
|
|
break;
|
|
case medeaState.TrafficPuzzle:
|
|
|
|
|
|
_currentRotSpeed = 0;
|
|
_medeaAI.angularSpeed = _currentRotSpeed;
|
|
|
|
thirdPerson.m_StationaryTurnSpeed = _currentRotSpeed;
|
|
thirdPerson.m_MovingTurnSpeed = _currentRotSpeed;
|
|
|
|
if (PlayerManager.GetInstance()._PlayerMovement._isRunning)
|
|
{
|
|
Debug.Log("you run you gdet killed");
|
|
DisableMedeaMeshRenderers();
|
|
state = medeaState.KillingPlayer;
|
|
}
|
|
|
|
if (PuzzlesManager.GetInstance().trafficLightsPuzzleData.lightsAreGreen)
|
|
{
|
|
_medeaAI.speed = 1.5f;
|
|
////If green she moves backwards
|
|
//_medeaAI.updatePosition = false;
|
|
//_medeaAI.isStopped = true;
|
|
|
|
//If green and the player gets too close to her then she disappears.
|
|
if (Vector3.Distance(_player.position, _medea.position) <= 0.5)
|
|
{
|
|
//Despawn
|
|
_medeaAI.speed = _defaultMovementSpeed;
|
|
medeaAnimator.SetBool("IsWalkingBackwards", false);
|
|
state = medeaState.Disabled;
|
|
//_medea.gameObject.SetActive(false);
|
|
}
|
|
|
|
if (PlayerManager.GetInstance()._PlayerMovement.isMoving)
|
|
{
|
|
//_medeaAI.updateRotation = false;
|
|
_medeaAI.isStopped = false;
|
|
_medeaAI.updatePosition = true;
|
|
_medeaAI.destination = PuzzlesManager.GetInstance().trafficLightsPuzzleData.medeaTrafficLightsStartPos.position;
|
|
medeaAnimator.SetBool("IsWalkingBackwards", true);
|
|
}
|
|
else
|
|
{
|
|
medeaAnimator.SetBool("IsWalkingBackwards", false);
|
|
//_medeaAI.updateRotation = true;
|
|
_medeaAI.updatePosition = false;
|
|
_medeaAI.isStopped = true;
|
|
}
|
|
}
|
|
else //if red
|
|
{
|
|
//if the player moves then medea moves as well in his direction.
|
|
//if he stops then medea stops.
|
|
//else the player doesn't move then medea doesn't move
|
|
|
|
if (PlayerManager.GetInstance()._PlayerMovement.isMoving)
|
|
{ /* _medeaAI.updateRotation = true;*/
|
|
_medeaAI.updatePosition = true;
|
|
_medeaAI.isStopped = false;
|
|
_medeaAI.speed = PlayerManager.GetInstance()._PlayerMovement._CurrentSpeed * 1.5f; //player speed=2.5//
|
|
_medeaAI.destination = _player.position;
|
|
}
|
|
else
|
|
{
|
|
//_medeaAI.updateRotation = true;
|
|
_medeaAI.speed = _defaultMovementSpeed;
|
|
_medeaAI.isStopped = true;
|
|
//_medeaAI.destination = _medeaAI.transform.position;
|
|
}
|
|
|
|
//if the player is too close to her, she kills the player
|
|
if (Vector3.Distance(_player.position, _medea.position) <= 0.5)
|
|
{
|
|
_medeaAI.speed = _defaultMovementSpeed;
|
|
_currentRotSpeed = _defaulfRotSpeed;
|
|
_medeaAI.angularSpeed = _defaulfRotSpeed;
|
|
|
|
thirdPerson.m_StationaryTurnSpeed = _defaultStationaryTurnSpeed;
|
|
thirdPerson.m_MovingTurnSpeed = _defaultMovingTurnSpeed;
|
|
|
|
state = medeaState.KillingPlayer;
|
|
}
|
|
}
|
|
|
|
break;
|
|
case medeaState.OrangeLights:
|
|
|
|
_currentRotSpeed = 0;
|
|
_medeaAI.angularSpeed = _currentRotSpeed;
|
|
|
|
thirdPerson.m_StationaryTurnSpeed = _currentRotSpeed;
|
|
thirdPerson.m_MovingTurnSpeed = _currentRotSpeed;
|
|
|
|
if (PlayerManager.GetInstance()._PlayerMovement._isRunning)
|
|
{
|
|
Debug.Log("You run, you get killed");
|
|
DisableMedeaMeshRenderers();
|
|
state = medeaState.KillingPlayer;
|
|
}
|
|
|
|
if (PuzzlesManager.GetInstance().trafficLightsPuzzleData.lightsAreGreen)
|
|
{
|
|
_medeaAI.speed = 1.5f;
|
|
|
|
if (Vector3.Distance(_player.position, _medea.position) <= 0.5)
|
|
{
|
|
_medeaAI.speed = _defaultMovementSpeed;
|
|
medeaAnimator.SetBool("IsWalkingBackwards", false);
|
|
state = medeaState.Disabled;
|
|
}
|
|
|
|
if (PlayerManager.GetInstance()._PlayerMovement.isMoving)
|
|
{
|
|
_medeaAI.isStopped = false;
|
|
_medeaAI.updatePosition = true;
|
|
_medeaAI.destination = PuzzlesManager.GetInstance().trafficLightsPuzzleData.medeaTrafficLightsStartPos.position;
|
|
medeaAnimator.SetBool("IsWalkingBackwards", true);
|
|
}
|
|
else
|
|
{
|
|
medeaAnimator.SetBool("IsWalkingBackwards", false);
|
|
_medeaAI.updatePosition = false;
|
|
_medeaAI.isStopped = true;
|
|
}
|
|
}
|
|
else if (PuzzlesManager.GetInstance().trafficLightsPuzzleData.lightsAreOrange) // New Orange Light State
|
|
{
|
|
_medeaAI.isStopped = true;
|
|
_medeaAI.speed = 0;
|
|
medeaAnimator.SetBool("IsFrozen", true);
|
|
|
|
// Implement logic to highlight the correct door
|
|
//PuzzlesManager.GetInstance().ShowCorrectDoor();
|
|
}
|
|
else // If Red Light
|
|
{
|
|
if (PlayerManager.GetInstance()._PlayerMovement.isMoving)
|
|
{
|
|
_medeaAI.updatePosition = true;
|
|
_medeaAI.isStopped = false;
|
|
_medeaAI.speed = PlayerManager.GetInstance()._PlayerMovement._CurrentSpeed * 1.5f;
|
|
_medeaAI.destination = _player.position;
|
|
}
|
|
else
|
|
{
|
|
_medeaAI.speed = _defaultMovementSpeed;
|
|
_medeaAI.isStopped = true;
|
|
}
|
|
|
|
if (Vector3.Distance(_player.position, _medea.position) <= 0.5)
|
|
{
|
|
_medeaAI.speed = _defaultMovementSpeed;
|
|
_currentRotSpeed = _defaulfRotSpeed;
|
|
_medeaAI.angularSpeed = _defaulfRotSpeed;
|
|
|
|
thirdPerson.m_StationaryTurnSpeed = _defaultStationaryTurnSpeed;
|
|
thirdPerson.m_MovingTurnSpeed = _defaultMovingTurnSpeed;
|
|
|
|
state = medeaState.KillingPlayer;
|
|
}
|
|
}
|
|
|
|
break;
|
|
default:
|
|
|
|
state = medeaState.Spawn;
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
void UpdateEnemyMovement()
|
|
{
|
|
//If agent has not reached the desired destination :
|
|
if (_medeaAI.remainingDistance > _medeaAI.stoppingDistance)
|
|
{
|
|
thirdPerson.Move(_medeaAI.desiredVelocity, false, false); //Agent is moving.
|
|
|
|
}
|
|
else //If agent has reached the desired destination :
|
|
{
|
|
thirdPerson.Move(Vector3.zero, false, false); //Agent stops moving.
|
|
}
|
|
}
|
|
|
|
public Vector3 DirFromAngle(float angleInDegrees, bool angleIsGlobal) // This calculate the angle of the viewpoint
|
|
{
|
|
if (!angleIsGlobal)
|
|
{
|
|
angleInDegrees += transform.eulerAngles.y;
|
|
}
|
|
return new Vector3(Mathf.Sin(angleInDegrees * Mathf.Deg2Rad), 0, Mathf.Cos(angleInDegrees * Mathf.Deg2Rad));
|
|
}
|
|
|
|
// This method is checking if pplayer is inside the view angle and callculates is there isnt any obstacle between the player and Medea
|
|
public bool CanSeePlayer()
|
|
{
|
|
Collider[] targetInViewRadius = Physics.OverlapSphere(transform.position, _viewRadius, playerMask);
|
|
|
|
if (targetInViewRadius.Length > 0)
|
|
{
|
|
_player = targetInViewRadius[0].transform;
|
|
Vector3 dirToTarget = (_player.position - transform.position).normalized;
|
|
|
|
if (Vector3.Angle(transform.forward, dirToTarget) < _viewAngle / 2)
|
|
{
|
|
float distToTarget = Vector3.Distance(transform.position, _player.position);
|
|
|
|
if (!Physics.Raycast(transform.position, dirToTarget, distToTarget, obstacleMask))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
public bool CanHearPlayer()
|
|
{
|
|
Collider[] targetInHearingRadius = Physics.OverlapSphere(transform.position, _hearingRadius, playerMask);
|
|
|
|
if (targetInHearingRadius.Length > 0)
|
|
{
|
|
_player = targetInHearingRadius[0].transform;
|
|
Vector3 dirToTarget = (_player.position - transform.position).normalized;
|
|
|
|
if (Vector3.Angle(transform.forward, dirToTarget) < _hearingAngle / 2)
|
|
{
|
|
float distToTarget = Vector3.Distance(transform.position, _player.position);
|
|
|
|
if (!Physics.Raycast(transform.position, dirToTarget, distToTarget, obstacleMask))
|
|
{
|
|
print("Ton akouw ton kariolh");
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
print("eimai koufh");
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// This method checks if Medea is alerted and Updates her view
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool IsAlerted()
|
|
{
|
|
if (CanSeePlayer())
|
|
{
|
|
_viewRadius = _alertedViewRadius;
|
|
_viewAngle = _alertedViewAngle;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
_viewAngle = _defaultViewAngle;
|
|
_viewRadius = _defaultViewRadius;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
//This method checks if the player is inside a hidding spot
|
|
public bool IsPlayerHidden()
|
|
{
|
|
if (HideManager.GetInstance().InCloset)
|
|
{
|
|
return true;
|
|
}
|
|
else if (HideManager.GetInstance().UnderBed)
|
|
{
|
|
return true;
|
|
}
|
|
else if (HideManager.GetInstance().UnderTable)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
public void DisableMedeaMeshRenderers()
|
|
{
|
|
foreach (SkinnedMeshRenderer medeaSkinnedMeshRenderer in _medeaSkinnedMeshRenderer)
|
|
{
|
|
medeaSkinnedMeshRenderer.enabled = false;
|
|
medeaMeshRenderersAreDisabled = true;
|
|
}
|
|
}
|
|
|
|
public void EnableMedeaMeshRenderers()
|
|
{
|
|
foreach (SkinnedMeshRenderer medeaSkinnedMeshRenderer in _medeaSkinnedMeshRenderer)
|
|
{
|
|
medeaSkinnedMeshRenderer.enabled = true;
|
|
medeaMeshRenderersAreDisabled = false;
|
|
}
|
|
}
|
|
|
|
public void StopSearchingAnimation()
|
|
{
|
|
//PatrolManager.GetInstance().HidePatrolPoints[PatrolManager.GetInstance()._destinationPoint - 1].parent.transform.parent.TryGetComponent<ClosetHideBehaviour>(out ClosetHideBehaviour _closetHideBehaviour);
|
|
//PatrolManager.GetInstance().HidePatrolPoints[PatrolManager.GetInstance()._destinationPoint -1].parent.transform.parent.TryGetComponent<BedHideBehaviourBase>(out BedHideBehaviourBase _bedHideBehaviour);
|
|
Debug.Log("Is trying to stop search cutscene circus!!!1");
|
|
if (PatrolManager.GetInstance().medeasCurrentPlayableDirector != null)
|
|
{
|
|
PatrolManager.GetInstance().medeasCurrentPlayableDirector.Stop();
|
|
PatrolManager.GetInstance().medeasCurrentPlayableDirector = null;
|
|
}
|
|
|
|
//if (_closetHideBehaviour != null)
|
|
//{
|
|
// _closetHideBehaviour.StopEnemyClosetSearchCutscene();
|
|
//}
|
|
//else if (_bedHideBehaviour != null)
|
|
//{
|
|
// _bedHideBehaviour.StopEnemyBedSearchCutscene();
|
|
//}
|
|
}
|
|
#region MedeaDespawn?
|
|
//IEnumerator MedeaDespawnAfterLosingPlayer()
|
|
//{
|
|
// Debug.Log("Medea will despawn");
|
|
// yield return new WaitForSeconds(300f);
|
|
// if(CanSeePlayer())
|
|
// {
|
|
// StopMedeaDespawn();
|
|
// }
|
|
|
|
//}
|
|
|
|
//public void StartMedeaDespawn()
|
|
//{
|
|
// _medeaDespawnTimer = StartCoroutine(MedeaDespawnAfterLosingPlayer());
|
|
//}
|
|
|
|
//public void StopMedeaDespawn()
|
|
//{
|
|
// StopCoroutine(_medeaDespawnTimer);
|
|
//}
|
|
#endregion
|
|
|
|
private void OnDrawGizmos()
|
|
{
|
|
#region GizmosForView
|
|
Gizmos.color = Color.yellow;
|
|
Gizmos.DrawWireSphere(transform.position, _viewRadius);
|
|
Vector3 viewAngleA = DirFromAngle(-_viewAngle / 2, false);
|
|
Vector3 viewAngleB = DirFromAngle(_viewAngle / 2, false);
|
|
Gizmos.DrawLine(transform.position, transform.position + viewAngleA * _viewRadius);
|
|
Gizmos.DrawLine(transform.position, transform.position + viewAngleB * _viewRadius);
|
|
Gizmos.DrawLine(transform.position, _player.position);
|
|
#endregion
|
|
|
|
#region GizmosForHearing
|
|
Gizmos.color = Color.blue;
|
|
Gizmos.DrawWireSphere(transform.position, _hearingRadius);
|
|
Vector3 hearingAngleA = DirFromAngle(-_hearingAngle / 2, false);
|
|
Vector3 hearingAngleB = DirFromAngle(_hearingAngle / 2, false);
|
|
Gizmos.DrawLine(transform.position, transform.position + hearingAngleA * _hearingRadius);
|
|
Gizmos.DrawLine(transform.position, transform.position + hearingAngleB * _hearingRadius);
|
|
Gizmos.DrawLine(transform.position, _player.position);
|
|
#endregion
|
|
}
|
|
}
|
|
|