void UpdateAudio(ZombieState argNewZombieState)
    {
        _audioManager.StopAllEvents();
        switch (argNewZombieState)
        {
        case ZombieState.IDLE:

        case ZombieState.WALKING:
            _audioManager.PlayEvent("_Idle");
            break;

        case ZombieState.CHASING:
            _audioManager.PlayEvent("_Chasing");
            break;

        case ZombieState.REACHING:
            _audioManager.PlayEvent("_Attack");
            break;

        case ZombieState.DEAD:
            _audioManager.PlayEvent("_Die");
            break;

        case ZombieState.PAUSED:
            _audioManager.StopAllEvents();
            break;
        }
    }
Example #2
0
 public void SetFreeze()
 {
     gameObject.tag          = "Untagged";
     rb.velocity             = new Vector3(0, 0, 0);
     State                   = ZombieState.Freeze;
     capsuleCollider.enabled = false;
 }
Example #3
0
    protected void AttackClosestObject()
    {
        //If Player cannot be reached, then the zombie searches for the closest object and goes to attack it by making the object the target of the seeker.
        int layerMask = 1 << 9;

        layerMask = ~layerMask;
        Vector2      directionPlayer = (player.position - transform.position);
        RaycastHit2D hit             = Physics2D.Raycast(transform.position, directionPlayer, Vector3.Distance(transform.position, player.transform.position), layerMask);

        Debug.DrawRay(transform.position, directionPlayer);
        Debug.Log("Tag " + hit.transform.tag);
        if (hit.transform.tag == "Base")
        {
            //Includes check the player isn't actually reachable in a straight line, covers for problem with A* and possible movement of the player
            target = StaticNodeLibrary.FindClosestWalkablePosition(hit.transform);
            Debug.Log(StaticNodeLibrary.FindClosestWalkablePosition(hit.transform));
            Debug.Log(hit.transform.tag);
            seeker.StartPath(transform.position, target, OnPathComplete);
        }
        else if (hit.transform.tag == "Player")
        {
            target = player.position;
            status = ZombieState.detected;
            seeker.StartPath(transform.position, target, OnPathComplete);
        }
    }
Example #4
0
 void ZombieStateUpdated(ZombieState argargZstate)
 {
     if (OnZombieStateChanged != null)
     {
         OnZombieStateChanged(argargZstate);
     }
 }
Example #5
0
    void CheckFollow()
    {
        if (followOrder > 5)
        {
            currentState = ZombieState.Dead;
            return;
        }

        float distance = (target.position - transform.position).magnitude;

        if (distance < followDistance)
        {
            zombieManager.AddFollowList(gameObject);
            int randOrder = Random.Range(1, 5);
            SetFollowOrder(randOrder);
            if (followOrder == 1)
            {
                attackTime   = 0;
                currentState = ZombieState.Attack;
            }
            else
            {
                currentState = ZombieState.Follow;
            }
        }
    }
Example #6
0
    void UpdateCollidersState(ZombieState argNewZombieState)
    {
        switch (argNewZombieState)
        {
        case ZombieState.IDLE:

        case ZombieState.WALKING:
            break;

        case ZombieState.CHASING:
            break;

        case ZombieState.REACHING:
            break;

        case ZombieState.DEAD:
            DisableBoxColliders(this.transform);
            CapsuleColliderEnable(false);
            FreezAllRigidBodyConstraints();
            break;

        case ZombieState.PAUSED:
            break;

        case ZombieState.MELTING:
            ClearRigidBodyConstraints();
            break;
        }
    }
Example #7
0
    // Update is called once per frame
    void Update()
    {
        //LookAtTarget (_targetPosition.position);
        //if( _state == ZombieState.Walk ){

        float distance = Vector3.Distance(this.transform.position, _targetPosition.position);

        //Debug.Log (distance);
        if (_state != ZombieState.Die)
        {
            if (distance > 5.0f)
            {
                _state = ZombieState.Walk;
                _controller.SimpleMove(this.gameObject.transform.forward * _speed);
            }
            else
            {
                _state = ZombieState.Act;
            }

            if (_state == ZombieState.Act)
            {
                TargetUIHP.GetInstance()._currentHp -= 0.03f;
            }
        }
        //SetMask ();
    }
Example #8
0
    void ChangeState(ZombieState newState)
    {
        mState = newState;
        switch (newState)
        {
        case (ZombieState.Walking):
        {
            break;
        }

        case (ZombieState.Idle):
        {
            break;
        }

        case (ZombieState.Dead):
        {
            break;
        }

        case (ZombieState.Attack):
        {
            break;
        }
        }
        mAnimator.SetInteger("state", (int)newState);
    }
Example #9
0
    void Update()
    {
        animTime -= Time.deltaTime;
        if (animTime < 0)
        {
            animTime = animDelayTime;
            if (spriteIndex == 0)
            {
                spriteIndex = 1;
            }
            else
            {
                spriteIndex = 0;
            }
            spriteRenderer.sprite = sprites[spriteIndex];
        }

        dicZombieState[currentState]();

        deadTime -= Time.deltaTime;
        if (transform.position.y < -10 || deadTime < 0)
        {
            currentState = ZombieState.Dead;
        }
    }
Example #10
0
 void Start()
 {
     playerObject = GameObject.FindWithTag("Player");
     zombieState  = ZombieState.Idle;
     animator     = GetComponent <Animator>(); //üstteki animatoru kullan
     agent        = GetComponent <NavMeshAgent>();
 }
Example #11
0
 void Init()
 {
     currentState = ZombieState.Idle;
     idleMovePos  = Vector3.zero;
     isAttacking  = false;
     moveSpeed    = Random.Range(0.0f, 0.7f);
 }
Example #12
0
    // Update is called once per frame
    void Update()
    {
        ZombieState state = getState();

        switch (state)
        {
        case ZombieState.Idle:
            m_animator.SetFloat(speed, 0f);
            break;

        case ZombieState.Walk:
            m_animator.SetFloat(speed, 1f);
            break;

        case ZombieState.Attack:
            Debug.Log("attack");
            m_animator.SetFloat(speed, 0.2f);
            m_animator.SetBool("go", false);
            m_animator.SetTrigger(attack);

            break;

        case ZombieState.Turn:
            break;

        default:
            break;
        }
        if (state == ZombieState.None)
        {
            return;
        }
        z_State = state;
    }
Example #13
0
 protected override void BeforeAwake()
 {
     _currentSpeed = _speed;
     _climbAnchors = FindObjectsOfType <ClimbAnchor>();
     _target       = FindObjectOfType <Knight>().gameObject;
     _state        = _initialState;
 }
Example #14
0
 protected override void FollowPlayer()
 {
     if (IsPlayerAround())
     {
         do
         {
             if (IsPaused)
             {
                 GameData.PauseGameEvent.Reset();
                 GameData.PauseGameEvent.WaitOne();
             }
             lock (GameData.ConsoleAccessObject)
             {
                 if (GameData.Player.Health > 0)
                 {
                     GameData.GameMechanics.HitPlayer(AttackDamage);
                     GameData.PlayerHealthStatusEvent.Set();
                 }
             }
             Thread.Sleep(AttackSpeed);
         } while (IsPlayerAround());
     }
     else
     {
         ZombieState.FindNextStep(this);
     }
 }
Example #15
0
 public Zombie(Game game)
     : base(game)
 {
     this.Impacts = new List<Impacts.IZombieImpact>();
     this.currentState = ZombieState.Walk;
     this.LP = 100;
 }
Example #16
0
    private void ChangeState(ZombieState newState)
    {
        activeState = newState;
        switch (activeState)
        {
        case ZombieState.STAND:
            movement.enabled = false;
            //movement.StopMovement();
            break;

        case ZombieState.MOVEtoPlayer:

            movement.enabled = true;
            break;

        case ZombieState.RETURN:

            movement.targetPosition = startPosition;
            movement.enabled        = true;
            break;

        case ZombieState.ATTACK:
            onCheckHeals();
            movement.enabled = false;
            // movement.StopMovement();
            break;
        }
    }
Example #17
0
        void PlayAnimation(ZombieState state)
        {
            switch (state)
            {
            case ZombieState.Idle:
            {
                animator.SetBool("IsWalking", false);
                animator.SetBool("IsRunning", false);
                animator.SetBool("IsPatrolling", false);
            }
            break;

            case ZombieState.Walking:
            {
                animator.SetBool("IsPatrolling", false);
                animator.SetBool("IsWalking", true);
            }
            break;

            case ZombieState.Running:
            {
                animator.SetBool("IsPatrolling", false);
                animator.SetBool("IsRunning", true);
            }
            break;

            case ZombieState.Patrolling:
            {
                animator.SetBool("IsRunning", false);
                animator.SetBool("IsWalking", false);
                animator.SetBool("IsPatrolling", true);
            }
            break;
            }
        }
Example #18
0
    private void ChangeState(ZombieState newState)
    {
        switch (newState)
        {
        case ZombieState.STAND:
            zombieMoving.StopMove();
            print("TO_STAND");
            break;

        case ZombieState.ROTATE_TO_PLAYER:
            zombieMoving.StopMove();
            print("TO_ROTATE_TO_PLAYER");
            break;

        case ZombieState.ATTACK:
            zombieMoving.StopMove();
            StartAttack();
            print("TO_ATTACK");
            break;

        case ZombieState.MOVE_TO_PLAYER:
            StopAttack();
            print("TO_MOVE_TO_PLAYER");
            break;

        case ZombieState.RETURN:
            print("TO_RETURN");
            break;

        case ZombieState.PATROL:
            print("TO_PATROL");
            break;
        }
        activeState = newState;
    }
Example #19
0
	void Start () 
	{
		health = 4;
		player = GameObject.FindGameObjectWithTag ("Player");
		state = new ZombieState_Locked (this);
		animator = GetComponent<Animator>();
	}
Example #20
0
    // Check to see if the zombie can see a target. If so, return true. Else, return false.
    bool Targeting()
    {
        if (!target)
        {
            didSpot = false;
            Vector3    dir = GameObject.FindGameObjectWithTag("Player").transform.position - transform.position;
            RaycastHit hit = new RaycastHit();
            Debug.DrawLine(transform.position + Vector3.up * headOffset, GameObject.FindGameObjectWithTag("Player").transform.position + Vector3.up * headOffset / 2, Color.red);

            Debug.DrawLine(transform.position + Vector3.up * headOffset, (transform.position + Vector3.up * headOffset) + transform.forward);

            //logic for modeling the zombie's field of view and make sure the potential target is not a zombie
            if (Mathf.Acos(Vector3.Dot(transform.forward, Vector3.Normalize(dir))) < Mathf.Deg2Rad * (FOV / 2f) &&
                Physics.Raycast(transform.position + Vector3.up * headOffset / 2, dir, out hit) &&
                hit.collider.gameObject.tag.Equals("Player"))
            {
                target = GameObject.FindGameObjectWithTag("Player").transform;

                state = ZombieState.chasing;
                print(hit.collider.gameObject.tag);
                return(true);
            }
        }
        return(false);
    }
    public Path PlotPath()
    {
        if (Node.CanReach(transform.position, Player.player.transform.position, LayerMasks.CanNodeReachPlayer))
        {
            return(new Path(new List <Node>(), Vector3.Distance(transform.position, Player.player.transform.position)));
        }

        IGraph subgraph = Graph.graph.GetSubgraph(transform.position);

        if (subgraph == null)
        {
            Debug.Log("Couldn't find subgraph");
            return(null);
        }

        bool[] marked = new bool[Graph.graph.GraphNodes.Count];
        for (int i = 0; i < subgraph.GraphNodes.Count; i++)
        {
            marked[i] = false;
        }
        PriorityQueue <ZombieState> queue = new PriorityQueue <ZombieState>();

        for (int i = 0; i < subgraph.GraphNodes.Count; i++)
        {
            float distance = Vector3.Distance(transform.position, subgraph.GraphNodes[i].Component.transform.position);
            if (Node.CanReach(transform.position, subgraph.GraphNodes[i].Component.transform.position, LayerMasks.CanNodeReachPlayer) && distance != 0)
            {
                marked[subgraph.GraphNodes[i].ID] = true;
                ZombieState state = new ZombieState(subgraph.GraphNodes[i], distance);
                queue.Push(state.f, state);
            }
        }

        ZombieState goal = null;

        while (queue.IsEmpty() == false)
        {
            goal = queue.Pop();
            if (goal.node.CanReachPlayer)
            {
                break;
            }
            for (int i = 0; i < goal.node.adjNodes.Count; i++)
            {
                if (marked[goal.node.adjNodes[i].node.ID] == false && goal.node.subIndex == goal.node.adjNodes[i].node.subIndex)
                {
                    ZombieState state = new ZombieState(goal, goal.node.adjNodes[i]);
                    marked[goal.node.adjNodes[i].node.ID] = true;
                    queue.Push(state.f, state);
                }
            }
        }

        if (goal == null)
        {
            return(new Path(new List <Node>(), 0));
        }

        return(goal.ToPath());
    }
Example #22
0
 //击飞动画计时
 private void FlyAniTimer()
 {
     //当处于击飞状态
     if (state == ZombieState.fly)
     {
         flyTimer += Time.deltaTime;
         //大于最大击飞时间,将状态设置为Run
         if (flyTimer >= Constant.ZombieAniTime.FLY_TIME)
         {
             state = ZombieState.run;
             //当Zombie世界坐标的Y值低于-14证明已经掉落到水面下
             if (transform.position.y < -14f)
             {
                 Destroy(this);//销毁自身
                 //transform.position = new Vector3(transform.position.x, 8.0f, transform.position.z);
             }
             else if (transform.position.y < -5f)    //只有当高度低于-5时,才会启动寻路
             {
                 flyTimer             = 0;
                 gameObject.layer     = 10; //设置层为Zombie层 10
                 NavMeshAgent.enabled = true;
             }
         }
     }
 }
 void Start()
 {
     gm             = Camera.main.GetComponent <GridManager>() as GridManager;
     player         = GameObject.Find("Player");
     state          = ZombieState.Wandering;
     targetPosition = transform.position;
 }
    override public void LookAround()
    {
        GameObject[] Zombies = (GameObject[])GameObject.FindObjectsOfType(typeof(GameObject));

        foreach (GameObject go in Zombies)
        {
            ZombieState z = go.GetComponent <ZombieState>();
            if (z == null || z == this)
            {
                continue;
            }

            Vector3 v            = go.transform.position - transform.position;
            float   distanceToGo = v.magnitude;

            if (distanceToGo < closestDistance)
            {
                if (z is ZombieState)
                {
                    closestDistance   = distanceToGo;
                    closestGameObject = go;
                }
            }

            if (distanceToGo > furthestDistance && distanceToGo < 10)
            {
                if (z is HumanState)
                {
                    furthestDistance   = distanceToGo;
                    furthestGameObject = go;
                }
            }
        }
    }
Example #25
0
 protected override void Spawn()
 {
     base.Spawn();
     player      = GameObject.Find("Player");
     state       = ZombieState.Idle;
     dmgModifier = 0;
     anim        = GetComponent <Animator>();
 }
Example #26
0
 // Start is called before the first frame update
 void Start()
 {
     ZombieRigidBody2D        = GetComponent <Rigidbody2D>();
     Rotation                 = 0;
     WanderTimer              = 0;
     CurrentState             = ZombieState.Wandering;
     WanderDecisionMakingTime = Random.Range(0, WanderingDecisionInterval);
 }
 public ZombieState(ZombieState prev, NodeConnection connection)
 {
     this.prev     = prev;
     this.distance = prev.distance + connection.distance;
     this.g        = prev.g + connection.distance + connection.node.Selected * 10;
     this.node     = connection.node;
     this.f        = this.g + node.DistanceToPlayer;
 }
 void UpdateLocomotion(ZombieState argNewZombieState)
 {
     if (argNewZombieState == ZombieState.MELTING)
     {
         meltStartPosition = transform.position;
         _isMelting        = true;
     }
 }
Example #29
0
    // Use this for initialization
    void Start()
    {
        state    = ZombieState.IDLE;
        animator = GetComponentsInChildren <Animator>();

        Debug.Log((int)state + " " + state);
        UpdateAnimation();
    }
 public ZombieState(Node node, float distance)
 {
     this.prev     = null;
     this.distance = distance;
     this.g        = distance + node.Selected * 10;
     this.node     = node;
     this.f        = this.g + node.DistanceToPlayer;
 }
 void AddToPath(ZombieState state, List <Node> path)
 {
     if (state != null)
     {
         AddToPath(state.prev, path);
         path.Add(state.node);
     }
 }
Example #32
0
 void ChangeState(ZombieStateEnum newState)
 {
     if (_currState != null)
     {
         _currState.OnExit(this);
     }
     _currState = _states[newState];
     _currState.OnEnter(this);
 }
Example #33
0
 public void SetStateToChase()
 {
     if(curState != ZombieSM.ZombieState.Die && curState != ZombieSM.ZombieState.Chase){
         curState = ZombieState.Chase;
         if (_chase != null) {  // the boss zombie does not have one
             _chase.PreCalculateChase();
         }
     }
 }
Example #34
0
    /*
    public void ControlledMovement(){
        // ZombieInfo.Animate.WalkDown(curAnim);
        CC.Move(Move);
    }*/
    public void SetStateToControlledMovement(Vector3 move)
    {
        Move = move;
        if(move.y < 0)
            ZombieInfo.Animate.WalkDown(curAnim);
        else
            ZombieInfo.Animate.WalkUp(curAnim);

        curState = ZombieState.ControlledMovement;
    }
Example #35
0
 void Awake()
 {
     if(Stoppable)
         curState = ZombieState.Stop;
     else if(Cutscene)
         curState = ZombieState.Cutscene;
     else
         curState = ZombieState.Wander;
     //curState = StartState;
 }
Example #36
0
        public Zombie(Zombie zombie)
            : base(zombie.Game)
        {
            this.currentState = zombie.currentState;

            this.Walk = new States.Walk(zombie.Walk);
            this.Attack = new States.Attack(zombie.Attack);
            this.Death = new States.Death(zombie.Death);
            this.LP = zombie.LP;
            this.Impacts = new List<Impacts.IZombieImpact>();
        }
Example #37
0
	public void ChangeState(ZombieState newState)
	{
		state.OnStateChange ();
		state = newState;
	}
    void Start()
    {
        zombieStates = ZombieState.fullHuman;

        //set default weapon stats
        currentProjectile = pistolBullet;
        currentBulletSpeed = pistolBulletSpeed;
        currDamage = pistolDamage;
        weaponSelected = WeaponSelect.pistol;
    }