Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / AI / Navmesh / Conditions / CanSeeCondition.cs
@Rackday Rackday on 21 Aug 748 bytes Project Added
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [CreateAssetMenu(menuName = "Finite State Machine/Condition/Can See Condition")]
  5. public class CanSeeCondition : Condition
  6. {
  7. public float viewAngle;
  8. public float viewDistance;
  9. protected override bool Test(FiniteStateMachine fsm)
  10. {
  11. Transform target = fsm.target;
  12. if (target != null)
  13. {
  14. Vector3 direction = target.position - fsm.transform.position;
  15. float distance = direction.magnitude;
  16. float angle = Vector3.Angle(direction.normalized, fsm.transform.forward);
  17. return (angle < viewAngle && distance < viewDistance);
  18. } else
  19. {
  20. return false;
  21. }
  22. }
  23. }