Example #1
0
    public override void _Ready()
    {
        GD.Randomize();

        stats = GetNode <Stats>("Stats");
        stats.OnZeroHealth += Death;

        hurtbox = GetNode <Hurtbox>("Hurtbox");
        hurtbox.OnInvincibilityEnded   += BlinkStop;
        hurtbox.OnInvincibilityStarted += BlinkStart;

        playerZone = GetNode <PlayerDetection>("PlayerDetection");
        batSprite  = GetNode <AnimatedSprite>("AnimatedSprite");

        softCollision = GetNode <SoftCollision>("SoftCollision");

        wanderController = GetNode <WanderController>("WanderController");

        rng = new RandomNumberGenerator();

        stateArray = new List <AIState> {
            AIState.IDLE, AIState.WANDER
        };

        state = PickRandomState(stateArray);

        animPlayer = GetNode <AnimationPlayer>("AnimationPlayer");
    }
Example #2
0
 void Awake()
 {
     stateHandler    = GetComponent <EnemyStateHandler>();
     playerDetection = GetComponent <PlayerDetection>();
     movement        = GetComponent <EnemyMovement>();
     gunHandler      = GetComponent <EnemyGunHandler>();
 }
Example #3
0
    int HEALTH = 2 + 1;     // idk why he takes damage instantly when spawning

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        audio           = GetNode <AudioStreamPlayer>("AudioStreamPlayer");
        playerDetection = GetNode <Area2D>("PlayerDetection") as PlayerDetection;
        animationPlayer = GetNode <AnimationPlayer>("AnimationPlayer");
        animationPlayer.Play("PreIdle");
    }
Example #4
0
    int HEALTH = 1 + 1; // idk why he takes damage instantly when spawning

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        audio           = GetNode <AudioStreamPlayer>("AudioStreamPlayer");
        audio.VolumeDb  = 2;
        animationPlayer = GetNode <AnimationPlayer>("AnimationPlayer");
        playerDetection = GetNode <Area2D>("PlayerDetection") as PlayerDetection;
    }
Example #5
0
 private void Awake()
 {
     navMeshAgent                 = GetComponent <NavMeshAgent>();
     playerDetection              = GetComponent <PlayerDetection>();
     playerDetection.OnDetection += PlayerDetection_OnDetection;
     animator = GetComponentInChildren <Animator>();
 }
Example #6
0
    void OnSceneGUI()
    {
        PlayerDetection fov = (PlayerDetection)target;

        Handles.color = Color.red;
        Handles.DrawWireArc(fov.transform.position, Vector3.up, Vector3.forward, 360, fov.attackRadius);
        Handles.color = Color.yellow;
        Handles.DrawWireArc(fov.transform.position, Vector3.up, Vector3.forward, 360, fov.viewRadius);
        Handles.color = new Color(0, 1, 1, .2f);
        Vector3 viewAngleA = fov.DirectionFromAngle(-fov.viewAngle / 2, false);
        Vector3 viewAngleB = fov.DirectionFromAngle(fov.viewAngle / 2, false);

        Handles.DrawLine(fov.transform.position, fov.transform.position + viewAngleA * fov.viewRadius);
        Handles.DrawLine(fov.transform.position, fov.transform.position + viewAngleB * fov.viewRadius);
        Handles.DrawSolidArc(fov.transform.position, fov.transform.up, viewAngleA, fov.viewAngle, fov.viewRadius);

        foreach (Transform visibleTarget in fov.visibleTargets)
        {
            if (Vector3.Distance(fov.transform.position, visibleTarget.position) < fov.attackRadius)
            {
                Handles.color = Color.red;
            }
            else
            {
                Handles.color = Color.yellow;
            }

            Handles.DrawLine(fov.transform.position, visibleTarget.position);
        }
    }
Example #7
0
 public void Initialize()
 {
     ThisPlayer   = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerControl>();
     ThisAnimator = this.gameObject.GetComponent <Animator>();
     ThisDetector = this.GetComponentInChildren <PlayerDetection>();
     ThisEnemy    = new EmptyEnemy();
 }
Example #8
0
    /// <summary>
    /// On collision with the enemy then check object tag and match with enemy.
    /// </summary>
    /// <param name="collision"> Default collision component.
    /// </param>
    private void OnCollisionEnter(Collision collision)
    {
        // if an enemy is collided.
        if (collision.gameObject.CompareTag("Enemy"))
        {
            // asssign the collided object to the current object.
            cObject = collision.gameObject;
            // detect the player from the enemies side.
            PD = cObject.GetComponentInParent <PlayerDetection>();
            // reduce health.
            health.takeDamage(PD.damage);
            // Destroy the script component.
            PD.isDestroyed();
            PD      = null;
            cObject = null;
        }

        // if collision is with an enemy projectile then take damage.
        if (collision.gameObject.CompareTag("Projectile"))
        {
            cObject = collision.gameObject;
            PJB     = cObject.GetComponentInParent <ProjectileBehaviour>();
            health.takeDamage(PJB.damage);
            PJB.IsDestroyed();
            PJB     = null;
            cObject = null;
        }
    }
Example #9
0
 void Start()
 {
     playerObj       = GameObject.FindGameObjectWithTag("Player"); // Find the player object
     src             = GetComponent <AudioSource>();               // Get audio source
     detectionScript = detectionZone.GetComponent <PlayerDetection>();
     detectionZone.transform.parent = null;                        // Make sure detection zone doesn't move with parent
 }
 public void Stunned(float stunTime)
 {
     StartCoroutine(StunnedZombieTimer(stunTime));
     destinationSetter         = gameObject.GetComponentInParent <AIDestinationSetter>();
     destinationSetter.enabled = false;
     playerDetection           = gameObject.GetComponentInParent <PlayerDetection>();
     playerDetection.enabled   = false;
 }
Example #11
0
 void Awake()
 {
     _detector    = transform.GetChild(0).GetComponent <PlayerDetection>();
     _postSearch  = GetComponentInChildren <FindPlayer>();
     _patrolBehav = GetComponent <Patrol>();
     _spriteHand  = GetComponent <Spritehandler>();
     _coneRender  = transform.GetChild(0).GetComponent <VisionConeRender>();
 }
Example #12
0
        private void Start()
        {
            //set components
            navigator = GetComponent <NavMeshAgent>();
            if (GetComponent <DetectionMeter>())
            {
                detection = GetComponent <DetectionMeter>();
            }

            if (pathParent && pathParent.GetComponent <PathController>())
            {
                pathController = pathParent.GetComponent <PathController>();
            }

            //set search pos
            lastKnownPlayerPosition = Vector3.zero;
            SearchPosition          = Vector3.zero;

            //set FOV
            CurrentFOV = patrolFOV;

            //set current point to first point
            if (pathController && pathController.listPoints.Count > 0)
            {
                currentPathPoint = pathController.listPoints[0];
            }
            currentListIndex = 0;

            //find the player
            if (player == null)
            {
                player = GameObject.FindGameObjectWithTag("Player");
                if (player == null)
                {
                    player = GameObject.FindGameObjectWithTag("Player");
                    if (player.transform.root.gameObject.tag == "Player")
                    {
                        player = player.transform.root.gameObject;
                    }
                }
            }

            //check if player has detection component
            if (player.GetComponent <PlayerDetection>())
            {
                playerDetection  = player.GetComponent <PlayerDetection>();
                playerComponents = playerDetection.components;
            }

            if (headTransform == null)
            {
                headTransform = transform;
            }

            //set state
            currentState = StealthState.PATROL;
            EnterPatrol();
        }
Example #13
0
 void Awake()
 {
     playerDetection = GetComponentInChildren <PlayerDetection>();
     if (playerDetection)
     {
         playerDetection.onEnemyEnter += OnEnemyEnter;
         playerDetection.onEnemyLeave += OnEnemyLeave;
     }
 }
 // Use this for initialization
 void Start()
 {
     //Getting components of the drone
     anim          = GetComponent <Animator>();
     playerDetect  = GetComponent <PlayerDetection>();
     droneMovement = GetComponent <DroneMovementManagement>();
     rb            = GetComponent <Rigidbody>();
     Pillars       = GameObject.FindGameObjectWithTag(name + "Pillars");
 }
 protected void AssignComponents()
 {
     _pathFinding    = GetComponentInParent <Pathfinding>();
     _patrolBehav    = GetComponentInParent <Patrol>();
     _soundHandler   = GetComponentInParent <GuardSoundHandler>();
     _spriteHandler  = GetComponentInParent <Spritehandler>();
     _playerDetector = GetComponent <PlayerDetection>();
     _visionCone     = GetComponent <LineRenderer>();
     _detection      = GetComponent <DetectionCommon>();
 }
Example #16
0
    int HEALTH = 3 + 1; // idk why he takes damage instantly when spawning

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        audio                = GetNode <AudioStreamPlayer>("AudioStreamPlayer");
        audio.VolumeDb       = 3;
        animationPlayer      = GetNode <AnimationPlayer>("AnimationPlayer");
        animationTree        = GetNode <AnimationTree>("AnimationTree");
        animationTree.Active = true;
        animationState       = animationTree.Get("parameters/playback") as AnimationNodeStateMachinePlayback;
        playerDetection      = GetNode <Area2D>("PlayerDetection") as PlayerDetection;
    }
    private void OnTriggerStay2D(Collider2D other)
    {
        PlayerDetection playerDetection = other.GetComponent <PlayerDetection>();

        if (playerDetection != null)
        {
            diamondEnemy.playerSpotted   = true;
            diamondEnemy.playerTransform = other.transform;
        }
    }
Example #18
0
    void Start()
    {
        enemy             = GetComponent <Rigidbody>();
        originalPosition  = transform.position;
        leftPos           = new Vector3(originalPosition.x - leftBoundry, originalPosition.y, 0f);
        rightPos          = new Vector3(originalPosition.x + rightBoundry, originalPosition.y, 0f);
        enemy.isKinematic = false;

        Player       = GameObject.Find("Yumi").transform;
        detectPlayer = this.GetComponentInChildren <PlayerDetection>();
    }
Example #19
0
    //public float time = 0f;
    //public bool canMoveSideways = true;

    void Awake()
    {
        rb              = this.GetComponent <Rigidbody> ();
        anim            = this.GetComponent <Animator> ();
        Physics.gravity = new Vector3(0, -20, 0);
        canMove         = true;
        thisName        = this.gameObject.name;
        pd              = this.GetComponent <PlayerDetection> ();
        dam             = this.GetComponent <DamageSetGet> ();
        ma              = this.GetComponent <MachineAverage> ();
    }
Example #20
0
    public bool GetCaughtByCops()
    {
        if (!GameManager.Instance().IsTargetAlive())
        {
            PlayerDetection playerDetection = player.GetComponent <PlayerDetection>();
            if (playerDetection.CopsWatchingYou())
            {
                GameManager.Instance().CinematicPlayerDie();
            }
        }

        return(false);
    }
Example #21
0
    void Start()
    {
        enemy             = GetComponent <Rigidbody>();
        enemy.isKinematic = false;

        Player       = GameObject.Find("Yumi").transform;
        detectPlayer = this.GetComponentInChildren <PlayerDetection>();

        originalPosition = transform.position;

        animator        = this.GetComponentInChildren <Animator>();
        sprite_renderer = this.GetComponentInChildren <SpriteRenderer>();
    }
Example #22
0
    void OnSceneGUI()
    {
        PlayerDetection fow = (PlayerDetection)target;

        Handles.color = Color.white;
        Handles.DrawWireArc(fow.transform.position, Vector3.up, Vector3.forward, 360, fow.viewRadius);
        Vector3 viewAngleA = fow.DirFromAngle(-fow.viewAngle / 2, false);
        Vector3 viewAngleB = fow.DirFromAngle(fow.viewAngle / 2, false);

        Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleA * fow.viewRadius);
        Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleB * fow.viewRadius);

        Handles.color = Color.red;
    }
Example #23
0
 private void Awake()
 {
     GameCamera                   = Camera.main;
     playerDetection              = GetComponent <PlayerDetection>();
     audioManager                 = GameObject.FindGameObjectWithTag("AudioManager").GetComponent <AudioManager>();
     playerDetection.OnDetection += PlayerDetection_OnDetection;
     enemyMaxHealth               = 5;
     health        = 5;
     minHealth     = 0;
     maxHealth     = 1;
     animator      = GetComponentInChildren <Animator>();
     em            = GetComponent <EnemyMovement>();
     stopAttacking = false;
 }
Example #24
0
    // Start is called before the first frame update
    void Start()
    {
        playerObj        = GameObject.FindGameObjectWithTag("Player");
        playerDetection  = detectors.GetComponent <PlayerDetection>();
        playerController = playerObj.GetComponent <PlayerController>();

        Transform[] patrolChildren = patrolWaypointParent.GetComponentsInChildren <Transform>();
        patrolWaypoints = new Vector3[patrolChildren.Length];

        for (int i = 0; i < patrolWaypoints.Length; i++)
        {
            patrolWaypoints[i] = patrolChildren[i].position;
        }
        Destroy(patrolWaypointParent);
    }
Example #25
0
 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     if (enemyTrash == null)
     {
         enemyTrash = animator.transform.gameObject.GetComponent <EnemyTrash>();
     }
     if (playerDetection == null)
     {
         playerDetection = animator.transform.gameObject.GetComponentInChildren <PlayerDetection>();
         artilleryRadius = playerDetection.artillery.GetComponent <CapsuleCollider>().radius;
     }
     animator.ResetTrigger("attackArtillery");
     enemyTrash.ChangeAttack("Attack");
     enemyTrash.nav.Stop();
 }
Example #26
0
    // Use this for initialization
    void Awake()
    {
        rb = GetComponent <Rigidbody>();
        sprite_renderer = GetComponentInChildren <SpriteRenderer>();
        startPos        = transform.position;
        tempPosition    = transform.position;

        pos1 = new Vector3(transform.position.x - leftBoundry, transform.position.y, 0f);
        pos2 = new Vector3(transform.position.x + rightBoundry, transform.position.y, 0f);

        Player       = GameObject.Find("Yumi").transform;
        detectPlayer = this.GetComponentInChildren <PlayerDetection>();

        frames        = 0;
        savedPosition = Vector3.zero;
    }
Example #27
0
    private void Awake()
    {
        idleState    = new IdleState(this);
        patrolState  = new PatrolSate(this);
        chaseState   = new ChaseState(this);
        attackState  = new AttackState(this);
        waitState    = new WaitState(this);
        searchState  = new SearchState(this);
        alertState   = new AlertState(this);
        protectState = new ProtectState(this);
        stunnedState = new StunnedState(this);

        //For color testing
        auxMesh = GetComponent <MeshRenderer>();
        //
        playerDetection = GetComponent <PlayerDetection>();
        attackRange     = playerDetection.attackRadius;
    }
Example #28
0
 /// <summary>
 /// Function that triggers when the player is continuing to collide with an enemy or a projectile
 /// </summary>
 /// <param name="collision">  Default collision component.
 /// </param>
 private void OnCollisionStay(Collision collision)
 {
     if (collision.gameObject.CompareTag("Enemy"))
     {
         cObject = collision.gameObject;
         PD      = cObject.GetComponentInParent <PlayerDetection>();
         health.takeDamage(PD.damage);
         Debug.Log("Collided with enemy, damage dealt is :" + cObject.name);
         PD.isDestroyed();
     }
     if (collision.gameObject.CompareTag("Projectile"))
     {
         cObject = collision.gameObject;
         PJB     = cObject.GetComponentInParent <ProjectileBehaviour>();
         health.takeDamage(PJB.damage);
         PJB.IsDestroyed();
         PJB     = null;
         cObject = null;
     }
 }
Example #29
0
    // Use this for initialization
    void Start()
    {
        playerDetection = GetComponentInChildren<PlayerDetection>();

        destinationList = new Vector3[destinationNodes.Length];
        for (int i = 0; i < destinationList.Length; i++) {
            destinationList[i] = destinationNodes[i].transform.position;
        }

        transform.position = destinationList[getClosestPoint()];

        //Debug.log (gameObject.transform.position + " " + destinationList [getClosestPoint ()]);
        //Debug.log(Vector3.Distance (gameObject.transform.position, destinationList [currentDestination]));

        fromPosition = transform.position;

        atVector = true;
        playerPosition = Vector3.zero;
        forwards = true;
        currentDestination = 0;
        waitTimer = 0.0f;

        gameObject.transform.LookAt (destinationList[currentDestination]);
    }
Example #30
0
 // Use this for initialization
 void Start()
 {
     //currentLevel = gameManager.getCurrentLevel ();
     audioSource = gameObject.AddComponent<AudioSource> ();
     audioSource.clip = noise;
     if (characterType != -1 || characterType != 0) {
         playerDetection = GetComponentInChildren<PlayerDetection>();
     }
 }
Example #31
0
    public bool IsSomeoneWatching()
    {
        PlayerDetection playerDetection = player.GetComponent <PlayerDetection>();

        return(playerDetection.IsPlayerVisible());
    }
Example #32
0
    public virtual void Start()
    {
        stats = GetComponent<EnemyStats>();
        patrolSpeed = stats.patrolSpeed;
        chaseSpeed = stats.chaseSpeed;
        chaseTime = stats.chaseTime;
        jumpHeight = stats.jumpHeight;
        pivotTime = stats.pivotTime;
        maxEnragedTimer = stats.maxEnragedTimer;
        maxRageTimer = stats.maxRageTimer;

        controller = GetComponent<Controller2D>();
        enemyAnimationController = GetComponent<Animator>();
        enemyCollider = GetComponent<BoxCollider2D>();
        playerDetection = transform.GetChild(0).GetComponent<PlayerDetection>();
        jumpPoints = transform.GetChild(1).gameObject;
        freeFallPoints = transform.GetChild(2).gameObject;
        player = FindObjectOfType<Player>().gameObject;

        CalculatePhysics();

        input = new Vector2(0, 0);

        airborne = false;
        isAttacking = false;
        changingDirection = false;
        patrolPathCreated = false;
        investigating = false;
        beingAttacked = false;

        enraged = false;
        buildingRage = false;
        losingRage = false;

        engagementCounter = chaseTime + pivotTime;

        eyePositionModifierX = (enemyCollider.size.x / 2) * .5f;
        eyePositionModifierY = (enemyCollider.size.y / 2) * .0f;

        jumpPoints = transform.GetChild(1).gameObject;

        CreatePatrolPath();
        state = EnemyState.Patroling;

        jumpPoint1 = jumpPoints.transform.GetChild(0).GetComponent<BoxCollider2D>();
        jumpPoint2 = jumpPoints.transform.GetChild(1).GetComponent<BoxCollider2D>();
        jumpPoint3 = jumpPoints.transform.GetChild(2).GetComponent<BoxCollider2D>();
        jumpPoint4 = jumpPoints.transform.GetChild(3).GetComponent<BoxCollider2D>();

        fallPoint1 = freeFallPoints.transform.GetChild(0).GetComponent<BoxCollider2D>();
        fallPoint2 = freeFallPoints.transform.GetChild(1).GetComponent<BoxCollider2D>();
        fallPoint3 = freeFallPoints.transform.GetChild(2).GetComponent<BoxCollider2D>();

        CalculateJumpCollders();
    }
Example #33
0
    void Awake()
    {
        currentHealth = startingHealth;
        attackTimer = 0f;
        poiTimer = 0f;
        turnTimer = 0f;
        destinationReached = false;
        alerted = false;
        playerInRange = false;
        damageTaken = false;
        direction = FacingDirection.Front;

        player = GameObject.FindWithTag("Player");
        playerScript = player.GetComponent<Player>();
        detection = player.GetComponentInChildren<PlayerDetection>();
        enemyRigidbody = GetComponent<Rigidbody2D>();
        if (ranged)
            attackScript = GetComponentInChildren<EnemyShooting>();
        else
            attackScript = GetComponentInChildren<EnemyMelee>();
        attackRangeCollider = attackScript.gameObject.GetComponent<CircleCollider2D>();
        attackRangeCollider.radius = attackScript.GetRange();
        anim = GetComponent<Animator>();
        points = new List<PointOfInterest>();
    }
 /*
  * Sets up script dependencies
  */
 void Awake()
 {
     _playerDetection = gameObject.GetComponentInChildren <PlayerDetection>();
     _pathfinding     = gameObject.GetComponent <Pathfinding>();
     map = GameObject.FindGameObjectWithTag("Map").GetComponent <NodeGenerator>().ReturnGeneratedGraph();
 }