Inheritance: MonoBehaviour
Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (transform.GetChild(0).GetComponent <Renderer>().isVisible)
        {
            healthBar.transform.parent.transform.position = Camera.main.WorldToScreenPoint(transform.position + new Vector3(0, 3, 0));
            healthBar.transform.localScale = (new Vector3(health_point / 5, 0.9f, 0));
        }
        transform.localPosition = new Vector3(transform.localPosition.x, 0.1f, transform.localPosition.z);
        FindTarget();
        //CheckSeparation();
        WolfStateMachine();
        MoveTarget();
        SoundDetection();
        if (gotSpray)
        {
            vulnerableTimer += Time.deltaTime;
            if (vulnerableTimer > 8)
            {
                gotSpray  = false;
                wolfState = WolfState.Wander;
            }
        }

        if (health_point <= 0)
        {
            if (GameObject.Find("Boundary1 (1)") != null)
            {
                GameObject.Find("Boundary1 (1)").SetActive(false);
            }
            die_ad.Play();
            Destroy(gameObject);
        }
    }
Example #2
0
    public void TakeDamage(int attack)  //受到伤害
    {
        if (state == WolfState.Death)
        {
            return;
        }

        target = GameObject.FindGameObjectWithTag(Tags.player).transform;  //受到攻击的时候小狼进行自动攻击
        state  = WolfState.Attack;

        float value = Random.Range(0f, 1f);

        if (value < miss)                                                //miss
        {
            AudioSource.PlayClipAtPoint(miss_sound, transform.position); //miss时候的声音
            hudText.Add("Miss", Color.grey, 0.1f);                       //显示miss效果
        }
        else  //打中
        {
            hp -= attack;
            hudText.Add("-" + attack, Color.red, 0.1f); //显示掉血量
            StartCoroutine(ShowBodyRed());              //使用协同方法
            if (hp <= 0)
            {
                state = WolfState.Death;
                Destroy(gameObject, 2);
            }
        }
    }
Example #3
0
    void FindTarget()
    {
        sound_detection_range = Physics.OverlapSphere(transform.position, range);
        wolves_in_range       = Physics.OverlapSphere(transform.position, 1);
        if (chaser == null && fow.visibleTargets.Contains(sesame.transform))
        {
            soundDetection = 20.1f;
            chaser         = this.gameObject;
            target         = sesame;
            wolfState      = WolfState.Pursue;
        }

        else if (chaser != gameObject && chaser != null)
        {
            wolfState = WolfState.Flank;
        }

        else if (gameObject == chaser && !fow.visibleTargets.Contains(sesame.transform))
        {
            chaser    = null;
            wolfState = WolfState.Wander;
        }

        else if (chaser == null && !fow.visibleTargets.Contains(sesame.transform))
        {
            wolfState = WolfState.Wander;
        }
    }
Example #4
0
    public void TakeDamage(int attack)
    {
        if (state == WolfState.Death)
        {
            return;
        }
        target = GameObject.FindGameObjectWithTag(tags.player).transform;
        state  = WolfState.Attack;
        float value = UnityEngine.Random.Range(0, 1f);

        if (value < miss_rate)
        {
            AudioSource.PlayClipAtPoint(miss_sound, transform.position);
            hudtext.Add("Miss", Color.gray, 1);
        }
        else
        {
            hudtext.Add("-" + attack, Color.red, 1);
            this.hp -= attack;
            StartCoroutine(showbodyRed());
            isattacked   = true;
            attack_timer = 0;
            if (hp <= 0)
            {
                state = WolfState.Death;
                Destroy(this.gameObject, 2);
            }
        }
    }
Example #5
0
    public void TakeDamage(int damage, float time = 0.1f)
    {
        if (wolfState == WolfState.Death)
        {
            return;
        }
        float value = Random.Range(0f, 1f);

        if (value < miss_rate)
        {
            StartCoroutine(AttackMiss());
        }
        else
        {
            hp -= damage;
            StartCoroutine("ShowBodyRed", time);
            if (hp <= 0)
            {
                PlayerStatus.Instance.AddExp(20);
                UIQuestSystem.Instance.KillCount++;
                wolfState = WolfState.Death;
                Destroy(this.gameObject, 0.5f);
            }
        }
    }
Example #6
0
    public void TakeDamage(int damageValue)
    {
        if (state == WolfState.Death)
        {
            return;
        }

        float value = Random.Range(0f, 1f);

        target = GameObject.FindGameObjectWithTag(Tags.player).transform;
        state  = WolfState.Attack;
        if (value <= dodgeProbability)
        {
            AudioSource.PlayClipAtPoint(missAudio, transform.position);
            hudText.Add("Miss", Color.gray, 1);
            return;
        }

        hudText.Add("-" + damageValue, Color.red, 1);
        StartCoroutine(ChangeBodyRed());
        hp -= damageValue;
        if (hp <= 0)
        {
            state = WolfState.Death;
        }
        else
        {
            animation.Play(takeDamageAnimationName);
        }
    }
Example #7
0
 private void CheckDistance()
 {
     if (Mathf.Abs(Vector3.Distance(this.transform.position, PlayerStatus.Instance.gameObject.transform.position)) < maxFindDistance)
     {
         if (isCanAttack == false)
         {
             isFindPlayer   = true;
             wolfState      = WolfState.Walk;
             currentAniName = walkString;
             animation1.CrossFade(currentAniName);
             this.transform.LookAt(PlayerStatus.Instance.transform.position);
             cc.SimpleMove(transform.forward * 1);
         }
         if (Mathf.Abs(Vector3.Distance(this.transform.position, PlayerStatus.Instance.gameObject.transform.position)) < maxAttackDistance)
         {
             isCanAttack = true;
             wolfState   = WolfState.Attack;
         }
         else
         {
             isCanAttack = false;
         }
     }
     else
     {
         isFindPlayer = false;
     }
 }
Example #8
0
    /// <summary>
    /// 受到伤害
    /// </summary>
    public void TakeDamage(int attack)
    {
        if (state == WolfState.Death)
        {
            return;
        }

        //转换为攻击状态
        state = WolfState.Attack;
        //target会被设置为null,所以要每一次受伤都设置
        target = player.transform;

        float value = Random.Range(0f, 1f);

        //miss效果
        if (value < miss)
        {
            AudioSource.PlayClipAtPoint(missSound, transform.position);
            hudText.Add("Miss", Color.gray, 1);
        }
        //打中
        else
        {
            ShowEffect();
            //掉血多少
            hudText.Add("-" + attack, Color.red, 1);

            hp -= attack;
            if (hp <= 0)
            {
                state = WolfState.Death;
            }
        }
    }
Example #9
0
    public void TakeDamage(int attack)  //受到伤害
    {
        if (state == WolfState.Death)
        {
            return;
        }
        target = GameObject.FindGameObjectWithTag(Tags.player).transform;
        state  = WolfState.Attack;
        float value = Random.Range(0f, 1f);

        if (value < miss_rate)  // Miss效果
        {
            AudioSource.PlayClipAtPoint(miss_sound, transform.position);
            hudtext.Add("Miss", Color.gray, 1);
        }
        else    //打中的效果
        {
            hudtext.Add("-" + attack, Color.red, 1);
            this.hp -= attack;
            StartCoroutine(ShowBodyRed());
            if (hp <= 0)
            {
                state = WolfState.Death;
                Destroy(this.gameObject, 2);
            }
        }
    }
Example #10
0
    //自动攻击
    public void AudoAttack()
    {
        if (target == null)
        {
            return;
        }
        float dis = Vector3.Distance(target.position, this.transform.position);

        if (dis > maxDistance)//超出范围
        {
            target = null;
            state  = WolfState.Idle;
        }
        else if (dis < mixDistance)//攻击
        {
            this.GetComponent <Animation>().CrossFade(attackNowName);
            attack_timer += Time.deltaTime;

            if (attack_timer > attack_date)
            {
                state        = WolfState.Idle;
                attack_timer = 0;
            }
            else
            {
                randomAttack();
            }
        }
        else//跟随
        {
            transform.LookAt(target);
            cc.SimpleMove(transform.forward * speed);
            this.GetComponent <Animation>().CrossFade("WolfBaby-Walk");
        }
    }
Example #11
0
    void Update()
    {
        if (state == WolfState.Death)
        {
            animation.CrossFade(deathAnimationName);
            Destroy(gameObject, 2);
        }
        else if (state == WolfState.Attack)
        {
            AutoAttack();
        }
        else if (state == WolfState.Idle)
        {
            animation.CrossFade(idleAnimationName);
        }
        else if (state == WolfState.Walk)
        {
            animation.CrossFade(walkAnimationName);
            controller.SimpleMove(transform.forward * speed);
        }

        if (state != WolfState.Death && state != WolfState.Attack && isAutoPatrol)
        {
            currentTime += Time.deltaTime;
            if (currentTime >= timer)
            {
                currentTime = 0;
                WolfState nextState = RandomState();
                state = nextState;
            }
        }
    }
Example #12
0
    void OnTriggerStay(Collider other)
    {
        if (!targetRabbit)
        {
            if (other.gameObject.CompareTag("rabbit") && !other.isTrigger && state == WolfState.RabbitSearching)
            {
                targetRabbit = other.gameObject.GetComponent <Rabbit>();
                state        = WolfState.Hunting;
            }
        }

        if (state == WolfState.MateSearching)
        {
            if (other.gameObject.CompareTag("wolf"))
            {
                //Generates garbage
                Wolf w = other.gameObject.GetComponent <Wolf>();

                if (w.state == WolfState.MateSearching && gender != w.gender)
                {
                    mate    = w;
                    state   = WolfState.MateTargeting;
                    w.mate  = this;
                    w.state = WolfState.MateTargeting;
                }
            }
        }
    }
Example #13
0
    protected override sealed void Target(int xCoord, int zCoord)
    {
        base.Target(xCoord, zCoord);

        if (currentX == xCoord && currentZ == zCoord)
        {
            if (state == WolfState.Hunting)
            {
                state = WolfState.Eating;
            }

            else if (state == WolfState.MateTargeting)
            {
                state = WolfState.Mating;
            }

            if (Mathf.Abs(targetZ) == 1 && Mathf.Abs(targetX) == 1)
            {
                targetX = 0;
            }
        }

        else
        {
            previousHopPoint = transform.position;
            targetHopPoint   = ecosystem.terrainManager.terrain[currentX, currentZ] + Vector3.up * 0.5f;
            currentlyHopping = true;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (state == WolfState.Death)
        {
            anim.CrossFade(anim_Death);
        }
        else if (state == WolfState.Idle)  //巡逻
        {
            anim.CrossFade(anim_current);

            if (anim_current == anim_Walk)
            {
                charControl.SimpleMove(transform.forward * 1);
            }
            timer += Time.deltaTime;
            if (timer >= time)
            {
                timer = 0;
                RandomState();
            }
        }
        else if (state == WolfState.Attack)
        {
            if (PlayerStatus._instance.State != PlayerState.Death)
            {
                Attack();
            }
            else
            {
                attack_target = null;
                state         = WolfState.Idle;
            }
        }
    }
Example #15
0
 private void EnterChaseState()
 {
     _musicPlayer.PlayWolfChaseSound(UnityEngine.Random.Range(0, 4));
     state = WolfState.Chase;
     chaseAnimationTimer = chaseAnimationSpeed;
     SetActiveModel(chaseModels[0]);
 }
Example #16
0
    void PerformStateAction()
    {
        int x = targetRabbit ? targetRabbit.currentX : 0;
        int z = targetRabbit ? targetRabbit.currentZ : 0;

        switch (state)
        {
        case WolfState.Searching:
            HopToNearbySquareAfterDelay(2, x, z);
            break;

        case WolfState.Hunting:
            if (!targetRabbit)
            {
                state = WolfState.Searching;
                if (Mathf.Abs(targetZ) == 1 && Mathf.Abs(targetX) == 1)
                {
                    targetX = 0;
                }
                return;
            }
            HopToNearbySquareAfterDelay(1, x, z);
            ClearRabbitWhenSafe();
            break;

        case WolfState.Dying:
            Die();
            break;

        case WolfState.Eating:
            EatRabbit();
            break;
        }
    }
 //受伤
 public void TakeDamage(int attack)
 {
     if (state != WolfState.Death)
     {
         target = temp;
         state  = WolfState.Attack;
         float value = Random.Range(0f, 1f);
         if (value < miss_rate)
         {
             hpfollow.MissTextControl();
             //miss
             wolf_audio.clip = miss_clip;
             wolf_audio.Play();
         }
         else
         {
             this.hp -= attack;
             hpfollow.DamageTextControl(attack);
             hpfollow.SliderControl();
             StartCoroutine(ShowBodyRed());
             if (hp <= 0)  //死亡
             {
                 state = WolfState.Death;
                 spawn.MinusNum();
                 BarNpc._instance.killCount++;
                 PlayerStatus._instance.GetExp(exp);
                 Destroy(this.gameObject, 1);
             }
         }
     }
 }
Example #18
0
 private void AutoAttack()
 {
     if (target != null)
     {
         PlayerState playerState = target.GetComponent <PlayerAttack>().state;
         if (playerState == PlayerState.Death)
         {
             target = null;
             state  = WolfState.Idle;
             return;
         }
         float distance = Vector3.Distance(target.position, transform.position);
         if (distance > maxDistance)
         {//停止自动攻击
             target = null;
             state  = WolfState.Idle;
         }
         else if (distance <= minDistance)
         {//自动攻击
             attack_timer += Time.deltaTime;
             animation.CrossFade(aniname_attack_now);
             transform.LookAt(target);
             if (aniname_attack_now == normalAttackAnimationName)
             {
                 if (attack_timer > time_normalattack)
                 {
                     //产生伤害
                     target.GetComponent <PlayerAttack>().TakeDamage(attack);
                     aniname_attack_now = idleAnimationName;
                 }
             }
             else if (aniname_attack_now == crazyAttackAnimationName)
             {
                 if (attack_timer > time_crazyattack)
                 {
                     //产生伤害
                     target.GetComponent <PlayerAttack>().TakeDamage(attack);
                     aniname_attack_now = idleAnimationName;
                 }
             }
             if (attack_timer > (1f / attack_rate))
             {
                 RandomAttack();
                 attack_timer = 0;
             }
         }
         else
         {//朝着角色移动
             transform.LookAt(target);
             controller.SimpleMove(transform.forward * speed);
             animation.CrossFade(walkAnimationName);
         }
     }
     else
     {
         state = WolfState.Idle;
     }
 }
Example #19
0
 int countSting = 1; //счетчик укусов, т.к. две-три могут укусить, музыка не может запускаться два раза
 void Werwolf_BeeSting(bool sting)
 {
     CurrentState = WolfState.GoAway; //у CurrentState вольфа надо было new, иначе из bee брал
     if (countSting == 1)
     {
         PlayMusicSting();
     }
     countSting++;
 }
Example #20
0
 void OnParticleCollision(GameObject other)
 {
     if (other.name.Contains("Smoke_Explosion_Loop_02"))
     {
         gotSpray        = true;
         vulnerableTimer = 0;
         wolfState       = WolfState.Flee;
     }
 }
Example #21
0
    private void EnterGrowlState()
    {
        _musicPlayer.PlayWolfGrowlSound(UnityEngine.Random.Range(0, 1));
        chaseTarget = null;
        state       = WolfState.Growl;

        remainingGrowlTime = maxGrowlTime;
        SetActiveModel(growlModel);
    }
Example #22
0
    protected override sealed void IncreaseHunger(float rate)
    {
        base.IncreaseHunger(rate);

        if (hunger >= 100)
        {
            state = WolfState.Dying;
        }
    }
Example #23
0
 public void MonsterWalkAround(Vector3 pos)
 {
     WolfMonster.transform.rotation = Quaternion.Slerp(WolfMonster.transform.rotation,
                                                       Quaternion.LookRotation(pos -
                                                                               new Vector3(transform.position.x, 0, transform.position.z)), 2 * Time.deltaTime);
     state = WolfState.WALK;
     MonsterStateControl();
     controller.Move(new Vector3(transform.forward.x, 0, transform.forward.z) * 2 * Time.deltaTime);
 }
Example #24
0
    void AutoAttack()  //小狼自动攻击
    {
        if (target != null)
        {
            playerAttack = target.GetComponent <PlayerAttack>();
            if (playerAttack.state == PlayerState.Death)  //人物死亡,停止攻击
            {
                target = null;
                state  = WolfState.Idle;
                return;
            }

            float distance = Vector3.Distance(transform.position, target.position);
            if (distance > maxDistance)  //人物超过距离,停止攻击
            {
                target = null;
                state  = WolfState.Idle;
            }
            else if (distance < minDistance)  //自动攻击
            {
                transform.LookAt(target);
                attack_timer += Time.deltaTime;
                GetComponent <Animation>().CrossFade(aniname_attack_now);
                if (aniname_attack_now == aniname_normalAttack) //攻击计时,普通攻击
                {
                    if (attack_timer > time_normalAttack)       //时间到了,攻击停止,产生伤害
                    {
                        target.GetComponent <PlayerAttack>().TakeDamage(attack_normal);
                        aniname_attack_now = aniname_idle;
                    }
                }
                else if (aniname_attack_now == aniname_crazyAttack) //攻击计时,普通攻击
                {
                    if (attack_timer > time_crazyAttack)            //时间到了,攻击停止,产生伤害
                    {
                        target.GetComponent <PlayerAttack>().TakeDamage(attack_crazy);
                        aniname_attack_now = aniname_idle;
                    }
                }
                if (attack_timer > (1f / attack_rate))  //再次进行攻击
                {
                    RandomAttack();
                    attack_timer = 0f;
                }
            }
            else  //朝向角色移动
            {
                transform.LookAt(target);
                GetComponent <Animation>().CrossFade(aniname_walk);
                cc.SimpleMove(transform.forward * speed);
            }
        }
        else
        {
            state = WolfState.Idle;
        }
    }
    public void _on_DamageArea_body_entered(Node body)
    {
        _state = WolfState.Attacking;

        if (body.Name == "Player")
        {
            float[] timeArg = { Damage };
            body.PropagateCall(nameof(Light.RemoveTimeFromTimer), new Array(timeArg));
        }
    }
Example #26
0
 public void takeDamage(int attack)
 {
     hp -= attack;
     StartCoroutine(takeRedEffect());
     if (hp < 0)
     {
         state = WolfState.Death;
         Destroy(this.gameObject, 2f);
     }
 }
    //自动攻击
    public void AutoAttack()
    {
        if (target.GetComponent <PlayerAttack>().state == PlayerState.Death)
        {
            target = null;
            state  = WolfState.Idle;
            return;
        }
        if (target != null)
        {
            float distance = Vector3.Distance(target.transform.position, transform.position);
            if (distance >= max_distance)
            {
                target = null;
                state  = WolfState.Idle;
            }
            else if (distance <= min_disitance)
            {
                //攻击
                attack_timer += Time.deltaTime;
                anim.CrossFade(anim_attackNow);
                if (anim_attackNow == anim_attack1)
                {
                    if (attack_timer >= attack1_time)
                    {
                        //伤害

                        target.GetComponent <PlayerAttack>().TakeDamage(attack);
                        anim_attackNow = anim_idle;
                    }
                }
                else if (anim_attackNow == anim_attack2)
                {
                    if (attack_timer >= attack2_time)
                    {
                        //伤害
                        target.GetComponent <PlayerAttack>().TakeDamage(attack * 2);
                        anim_attackNow = anim_idle;
                    }
                }
                if (attack_timer >= (1f / attack_rate))
                {
                    attack_timer = 0;
                    RandomAttack();
                }
            }
            else
            {
                transform.LookAt(target.transform);
                controller.SimpleMove(transform.forward * speed);
                anim.CrossFade(anim_walk);
            }
        }
    }
Example #28
0
 void OnTriggerStay(Collider other)
 {
     if (!targetRabbit)
     {
         if (other.gameObject.CompareTag("rabbit") && !other.isTrigger)
         {
             targetRabbit = other.gameObject.GetComponent <Rabbit>();
             state        = WolfState.Hunting;
         }
     }
 }
Example #29
0
 private void AutoAttack()
 {
     if (target != null)
     {
         PlayerState plyerState = target.GetComponent <playerattack>().state;
         if (plyerState == PlayerState.Death)
         {
             target = null;
             state  = WolfState.Idle; return;
         }
         float distance = Vector3.Distance(target.position, transform.position);
         if (distance > maxdistance)
         {
             target = null;
             state  = WolfState.Idle;
         }
         else if (distance <= mindistance)
         {
             attack_timer += Time.deltaTime;
             animations.CrossFade(aniname_attack_now);
             if (aniname_attack_now == aniname_normalattack)
             {
                 if (attack_timer > time_normalattack)
                 {
                     target.GetComponent <playerattack>().TakeDamage(attack);
                     aniname_attack_now = animname_idle;
                 }
             }
             else if (aniname_attack_now == aniname_crazyattack)
             {
                 if (attack_timer > time_crazyattack)
                 {
                     target.GetComponent <playerattack>().TakeDamage(attack);
                     aniname_attack_now = animname_idle;
                 }
             }
             if (attack_timer > (1f / attack_rate))
             {
                 RandomAttack();
                 attack_timer = 0;
             }
         }
         else
         {
             transform.LookAt(target);
             cc.SimpleMove(transform.forward * speed);
             animations.CrossFade(animname_walk);
         }
     }
     else
     {
         state = WolfState.Idle;
     }
 }
Example #30
0
 public Werwolf(World_1 world) : base()
 {
     this.hero    = world.hero;
     Location     = world.verfolfBeginLocation;
     CurrentState = WolfState.Stay;
     this.world   = world;
     //подписываемся на укус пчел
     foreach (Bee bee in world.bees)
     {
         bee.BeeBeeSting += Werwolf_BeeSting;
     }
 }
Example #31
0
	public void TakeDamge(int attack){
		if(state == WolfState.Death) return;
		state = WolfState.Attack;
		target = GameObject.FindGameObjectWithTag ("Player").transform;
		float value = Random.Range (0f, 1f);
		//miss, don't hit the wolf
		if (value < missRate) {
			hudtext.Add("Miss",Color.gray,1);
		}
		//hit the wolf
		else {
			//show the missing hp
			hudtext.Add("-"+attack,Color.red,1);
			this.hp -= attack;
			StartCoroutine(ShowBodyRed());
			isAttack = true;
			attackTimer = 0;
			//if the hp is less than 0,the wolf must be dead
			if(hp<=0){
				state = WolfState.Death;
				Destroy(this.gameObject, 2);
			}
		}
	}
Example #32
0
    /// <summary>
    /// the calcSteeringForces method used by wolves.
    /// </summary>
    protected override void calcSteeringForces()
    {
        switch (state) {
        case WolfState.TRACK:
            {
                maxSpeed = walkMaxSpeed;
                //only the leader needs to steer
                //tracking behavior
                //wander, make wandering fight a little with finding the deer

                //Debug.Log(flock.leader);
                if(flock.leader == this.id)
                {
                    steeringForce+= wander()*wanderWeight;
                    //head towards the closest deer
                    GameObject[] deer = GameObject.FindGameObjectsWithTag("deer");
                    List<Flocker> deerList = new List<Flocker>();
                    foreach(GameObject d in deer)
                    {
                        deerList.Add(d.GetComponent<Flocker>());
                    }
                    int index = getNearest(deerList);
                    //Debug.Log(deerList.Count);
                    if (index != -1)
                    {
                        //Debug.Log("index not -1");
                        if(deerList[index]!=null)
                            steeringForce += seek(deerList[index].transform.position) * seekWeight;
                    }
                }
                //leader following
                else
                {
                    //having them all follow the same leader should pretty much give us cohesion and alignment without trying
                   // Debug.Log("calling follow");
                    steeringForce += followLeader(flock.Flockers[0],followDistance)*followWeight;
                    steeringForce += separation(separateDistance)*separationWeight;
                }
                //everyone avoids obstacles
                foreach (GameObject obstacle in gm.Obstacles)
                {
                    steeringForce += avoid(obstacle) * avoidWeight;
                }
                steeringForce += stayInBounds() * boundsWeight;
                foreach(Flock dflock in gm.Herds)
                {
                    if((this.flock.Centroid - dflock.Centroid).sqrMagnitude < huntDistance * huntDistance)
                    {
                        huntFlock = dflock;
                        state = WolfState.HUNT;
                        Debug.Log("change state to hunt");
                    }

                }
                break;
            }
        case WolfState.HUNT:
            {
                //if (isHerder) //if you're supposed to be containing, contain!
                //{
                   // maxSpeed = runMaxSpeed*1.5f;
                    //Debug.Log("herding");
                    //steeringForce += herd();
                //}
                //else //otherwise, try to catch the nearest deer
                //{
                    //Debug.Log("hunting");
                    maxSpeed = runMaxSpeed;
                    int nearestIndex;
                    if (huntFlock != null)
                        nearestIndex = getNearest(huntFlock.Flockers);
                    else
                        nearestIndex = -1;
                    if (nearestIndex > -1)
                    {
                        if(huntFlock.Flockers[nearestIndex] != null)
                            steeringForce+=pursue(huntFlock.Flockers[nearestIndex]);

                    }
                    else
                        Debug.Log("hunt index -1");

                //}
                    //deer collision detection
                if(huntFlock != null)
                    foreach(Flocker f in huntFlock.Flockers)
                    {
                      if(f!=null)
                        if(checkCollide(f))
                        {

                            foreach(Flocker w in flock.Flockers)
                                w.GetComponent<wolfScript>().state = WolfState.EAT;
                            huntFlock = null;
                            Debug.Log("change state to eat");
                            downDeer = f.transform.position;
                            //the deer shouldn't be in a flock anymore, so don't need to clean that up..
                            //we dynamically grabbed the master list of deer so that's not an issue...
                            //so theoretically it should be safe to just throw it out now.
                            f.kill();
                            //possibly instantiate a static dead deer here if there's time, but for now it's ok for them to just disappear
                            //start timer
                            time = 0.0f;
                            return;
                        }
                    }
                foreach (GameObject obstacle in gm.Obstacles)
                {
                    steeringForce += avoid(obstacle) * avoidWeight;
                }
                steeringForce += separation(separateDistance) * separationWeight;
                break;
            }
        case WolfState.EAT:
            {

                //eating behavior
                steeringForce += arrive(downDeer);
                steeringForce += separation (separateDistance)*separationWeight;
                time += Time.deltaTime;
                if(time >= feedtime)
                {
                    Debug.Log("reset");
                    downDeer = Vector3.zero;
                    state = WolfState.TRACK;
                    time = 0.0f;

                }
                foreach (GameObject obstacle in gm.Obstacles)
                {
                    steeringForce += avoid(obstacle) * avoidWeight;
                }
                break;
            }

        }
        steeringForce += stayInBounds() * boundsWeight;
        base.calcSteeringForces();
    }
Example #33
0
	void AutoAttack(){
		//no target to attack
		if (target != null) {
			PlayerState playerState = target.GetComponent<PlayerAttack>().state;
			if(playerState == PlayerState.Death){
				//stop auto attack
				target = null;
				state = WolfState.Idle;
				return;
			}
			float distance = Vector3.Distance(target.position, transform.position);
			if(distance > maxDistance){
				//stop auto attack
				target = null;
				state = WolfState.Idle;
			} else if(distance < minDistance){
				transform.LookAt(target);
				//do the auto attack
				attackTimer += Time.deltaTime;
				animation.CrossFade(animationAttackCurrent);
				//normal attack
				if(animationAttackCurrent == animationNormalAttack){
					//the attack animation has been played over
					if(attackTimer > timeNormalAttack){
						//cause the damager
						target.GetComponent<PlayerAttack>().TakeDamage(attack);
						//reset to the idle
						animationAttackCurrent = animationIdle;
					} 
				} 
				//crazy attack
				else if(animationAttackCurrent == animationCrazyAttack){
					if(attackTimer > timeCrazyAttack){
						//cause the damager
						//TODO
						//reset to the idle
						animationAttackCurrent = animationIdle;
					}
				}
				if(attackTimer > (1f/attackRate)){
					//attack again
					RandomAttack();
					//reset timer to 0
					attackTimer = 0;
				}
			} else {
				//distance between the max and min distance
				//move towrads to the player
				transform.LookAt(target);
				babyController.SimpleMove(transform.forward * moveSpeed);
				animation.CrossFade(animationWalk);
			}
		} else {
			state = WolfState.Idle;
		}
	}