Example #1
0
    void FixedUpdate()
    {
        ai.fpscounter++;
        aidirection = attackingg.transform.position - gameObject.transform.position;

        RaycastHit2D hit = Physics2D.Raycast(gameObject.transform.position, aidirection, 12.0f, Wall);

        if (hit.collider != null && hit.collider.tag == "Player")
        {
            visible = true;
        }
        else
        {
            visible = false;
        }

        if (visible)
        {
            if (getDistance(attackingg) < 10.0f)
            {
                this.setDirection(aidirection);
                Move();
                isBlindlyChasing = false; //name innacurate because of this, but #YOLO
            }
            else
            {
                isBlindlyChasing = true;
            }
            if (isWandering && getDistance(attackingg) >= 10.0f)
            {
                actuallyRePath(attackingg.transform.position);
            }

            isWandering  = false;
            lastTimeSeen = Time.time;
        }
        else if (!visible && (Time.time - lastTimeSeen < chaseTimeOut))
        {
            isBlindlyChasing = true;
            isWandering      = false;
        }
        else
        {
            if (isBlindlyChasing)
            {
                actuallyRePath(attackingg.transform.position);
            }
            isWandering      = true;
            isBlindlyChasing = false;
        }



        if (isWandering)
        {
            if (ai.currentNode == null)
            {
                eTile[,] map = mapgen.currentFloor();
                Location randomPlace;
                do
                {
                    randomPlace = new Location(Random.Range(0, map.GetLength(0)), Random.Range(0, map.GetLength(1)));
                }while (map[randomPlace.x, randomPlace.y] != eTile.Floor);

                randomTarget = new Vector3(randomPlace.x, randomPlace.y, 0);

                PathFindTowards(randomTarget);
            }
            else
            {
                PathFindTowards(randomTarget);
            }
        }

        if (isBlindlyChasing)
        {
            PathFindTowards(attackingg.transform.position);
        }



        if (name.Equals("Ghost") && getDistance(attackingg) < 60 && GetComponent <Status>().see)
        {
            //if (getDistance (attackingg) < 60 && GetComponent<Status>().see) {
            AutoTarget.cast(attackingg);
            //Debug.Log ("123");
            //Debug.Log(attackingg.tag);
        }
    }
Example #2
0
    private void FixedUpdate()
    //walkDirection: 1 = left, 2 = up, 3 = right, 4 = down;
    //idleDirection: saves previous walkDirection to animate idle
    {
        float dx = 0;
        float dy = 0;

        if (!gameObject.GetComponent <Status>().isStunned)
        {
            if (Input.GetAxisRaw("Vertical") > 0)
            {
                anim.SetInteger("direction", 2);
                anim.SetFloat("velocity", 1.0f);
                previousDirection = 2;
                dy = 1;
            }
            if (Input.GetAxisRaw("Horizontal") < 0)
            {
                //anim.SetBool("a", true);
                //anim.SetBool("d", false);

                anim.SetInteger("direction", 1);
                anim.SetFloat("velocity", 1.0f);
                previousDirection = 3;
                dx = -1;
            }
            if (Input.GetAxisRaw("Vertical") < 0)
            {
//				if (!Input.GetKey (KeyCode.A) && !Input.GetKey (KeyCode.LeftArrow))
                anim.SetInteger("direction", 4);
                anim.SetFloat("velocity", 1.0f);
                previousDirection = 4;
                dy = -1;
            }
            if (Input.GetAxisRaw("Horizontal") > 0)
            {
//				Vector3 theScale = transform.localScale;
//				theScale.x = 1;
//				transform.localScale = theScale;

                anim.SetInteger("direction", 1);
                anim.SetFloat("velocity", 1.0f);
                previousDirection = 1;
                dx = 1;
            }
            //
            if (Input.GetButton("Heal"))
            {
                SelfCast.cast(gameObject);
            }

            if (Input.GetButton("PoisonCloud"))
            {
                SelfCast2.cast(gameObject);
            }

            if (Input.GetButton("Fireball"))
            {
                AutoTarget.cast(cStat.FindClosestEnemy());
            }

            if (Input.GetButton("Clayball"))
            {
                AutoTarget2.cast(cStat.FindClosestEnemy());
            }
            if (Input.GetMouseButtonDown(0))
            {
                PosTarget.cast(Input.mousePosition);
            }
        }
        //if not moving
        if (!PlayerInput.isMoving())
        {
            anim.SetInteger("direction", previousDirection);
            anim.SetFloat("velocity", 0.0f);
        }

        this.setDirection(new Vector3(dx, dy, 0));
        Move();

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (paused)
            {
                paused           = false;
                playerGUI.paused = false;
            }
            else
            {
                paused           = true;
                playerGUI.paused = true;
            }
        }

        if (gameObject.GetComponent <Status>() != null && gameObject.GetComponent <Status> ().getHealth() < 0)
        {
            Die();
        }

        UpdateGameState();
    }