Exemple #1
0
    protected virtual void InSightState()
    {
        pf.FollowPath();

        timer -= Time.deltaTime;

        if (timer < 0.0)
        {
            timer = updatePathTime;

            entity = (pf.CurrentPath() != Pathfollowing.PathState.CIRCLE) ?
                     vc.GetObjectInVisionCone(vc.locateRadius) :
                     vc.GetObjectInVisionCone(0f);

            if (entity == null)
            {
                currentState = SharkState.LOSS_SIGHT;
                LossSightStateStart();
            }
            else
            {
                float distance = VectorUtility.distance(transform.position, entity.transform.position);
                if (distance < circlePathDistance && (pf.CurrentPath() != Pathfollowing.PathState.CIRCLE))
                {
                    pf.GenerateCirclePath(entity.transform.position);
                }
                else if (distance > circlePathDistance)
                {
                    pf.GenerateHeadToPath(entity.transform.position);
                }
            }
        }
    }
Exemple #2
0
        private void DecideBehavior()
        {
            // Debug.Log(diverRef.IsHiding());

            if (isPlayerSpotted)
            {
                if (diverRef.IsHiding())
                {
                    isPlayerSpotted  = false;
                    lastSeenPosition = diverRef.GetLastHidingPosition();
                    sharkState       = SharkState.INVESTIGATING;
                }
                else
                {
                    sharkState = SharkState.ATTACKING;
                }
            }
            else
            {
                if (sharkState == SharkState.ATTACKING)
                {
                    sharkState = SharkState.INVESTIGATING;
                }

                if (sharkState == SharkState.INVESTIGATING)
                {
                    if (Vector3.Distance(transform.position, lastSeenPosition) <= Mathf.Epsilon)
                    {
                        sharkState = SharkState.PATROLLING;
                    }
                }
            }
        }
Exemple #3
0
    void Start()
    {
        patrolColour = new Gradient();
        patrolColour.SetKeys(
            new GradientColorKey[] { new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.green, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) }
            );

        roamColour = new Gradient();
        roamColour.SetKeys(
            new GradientColorKey[] { new GradientColorKey(Color.white, 0.0f), new GradientColorKey(Color.white, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) }
            );

        inSightColour = new Gradient();
        inSightColour.SetKeys(
            new GradientColorKey[] { new GradientColorKey(Color.red, 0.0f), new GradientColorKey(Color.red, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) }
            );

        lossSightColour = new Gradient();
        lossSightColour.SetKeys(
            new GradientColorKey[] { new GradientColorKey(Color.yellow, 0.0f), new GradientColorKey(Color.yellow, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) }
            );


        pf.GeneratePath();
        currentState = SharkState.PATROL;
        PatrolStateStart(true);
    }
Exemple #4
0
 void Start()
 {
     target        = origin = transform.position;
     state         = SharkState.RESTING;
     player        = GameObject.FindGameObjectWithTag("Player");
     player_script = player.GetComponent <Player>();
     transform.GetChild(0).gameObject.SetActive(false);
     animator = GetComponent <Animator>();
 }
Exemple #5
0
    static bool Prefix(SharkState newState)
    {
        if (newState == SharkState.AttackPlayer && EarlsMod.settings.sharkDisabled)
        {
            return(false);
        }

        return(true);
    }
Exemple #6
0
 public void SetState(SharkState pState)
 {
     if (_abstractState != null)
     {
         _abstractState.Refresh();
     }
     _abstractState = _stateCache[pState];
     _abstractState.Start();
 }
    IEnumerator Cooldown()
    {
        m_SharkState = SharkState.Cooldown;
        yield return(new WaitForSeconds(0.5f));

        OpenMouth(true);
        yield return(new WaitForSeconds(2.0f));

        m_WanderGoal = Vector3.zero;
        m_SharkState = SharkState.Wandering;
    }
 public void BePassive()
 {
     if (enemyHealth <= 0)
     {
     }
     else
     {
         attackCollider.enabled = false;
         sharkState             = SharkState.Idle;
         attackTriggered        = false;
         DetermineState();
     }
 }
Exemple #9
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.collider.CompareTag("Turtle") && currentState == SharkState.CHARGING)
     {
         targetVel    = Vector3.zero;
         currentState = SharkState.FEEDING;
         feedingTime  = 5.0f;
     }
     else
     {
         currentState = SharkState.RISING;
     }
 }
Exemple #10
0
    private void FixedUpdate()
    {
        SharkState sharkState = (!(sensor.waterBody != null)) ? SharkState.Ground : SharkState.Water;

        if (m_State != sharkState)
        {
            ChangeSharkState(sharkState);
        }
        if (currentState != null)
        {
            currentState.MoveNext();
        }
        ApplyForces();
    }
Exemple #11
0
    private void ChangeSharkState(SharkState state)
    {
        switch (state)
        {
        case SharkState.Water:
            currentState = SwimState();
            break;

        case SharkState.Ground:
            currentState = FlopState();
            break;
        }
        m_State = state;
    }
Exemple #12
0
 void GlobalMessage(string message)
 {
     Debug.Log("GlobalMessage :" + message);
     if (message == "pause")
     {
         mSharkPrevState = mSharkState;
         mSharkState     = SharkState.Pause;
     }
     else if (message == "play")
     {
         if (mSharkState == SharkState.Pause)
         {
             mSharkState = mSharkPrevState;
         }
     }
 }
    new void Update()
    {
        base.Update();

        switch (m_SharkState)
        {
        case SharkState.Wandering:
        {
            if (m_WanderGoal == Vector3.zero || Vector3.Distance(transform.position, m_WanderGoal) < 5.0f)
            {
                m_WanderGoal = GetWanderSpot();
            }
            Vector3 direction = m_WanderGoal - transform.position;

            /*transform.rotation = Quaternion.Slerp(transform.rotation,
             *  Quaternion.LookRotation(direction),
             *  m_TurnSpeed * Time.deltaTime);
             * transform.Translate(Vector3.forward * m_WanderSpeed * Time.deltaTime);*/
            TurnTowards(direction);
            MoveForward(m_WanderForce);
        }
        break;

        case SharkState.Hunting:
        {
            if (!m_WanderBounds.Contains(m_Prey.transform.position))
            {
                m_SharkState = SharkState.Wandering;
                return;
            }

            Vector3 direction = m_Prey.transform.position - transform.position;
            TurnTowards(direction);
            MoveForward(m_HuntForce);

            if (Vector3.Distance(m_Prey.transform.position, transform.position) < 5.0f &&
                Vector3.Dot(m_Prey.transform.position - transform.position, transform.forward) > 0)
            {
                //OpenMouth(true);
                //Strike(direction);
                Strike();
                StartCoroutine(Cooldown());
            }
        }
        break;
        }
    }
Exemple #14
0
    void Reproduction()
    {
        numberOfSpawn = Random.Range(1, 2);

        bool otherSharksPresent = false;

        for (int i = 0; i < sharkManager.allSharks.Count; i++)
        {
            if (sharkManager.allSharks[i] != this.gameObject &&
                sharkManager.allSharks[i].GetComponent <SharkHealth>().male) // If there is another shark in scene and it is a male
            {
                otherSharksPresent = true;
            }
        }

        if (otherSharksPresent &&
            currentSharkState == SharkState.ReadyToReproduce &&
            canReproduce)
        {
            currentSharkState = SharkState.Reproducing; // Change state to reproducing
        }

        if (currentSharkState == SharkState.Reproducing)
        {
            gestationPeriod -= Time.deltaTime; // Reduces the time to spawn another fish

            if (gestationPeriod <= 0)
            {
                for (int i = 0; i < numberOfSpawn; i++)
                {
                    sharkManager.lifetimeSharkCount++;
                    sharkManager.allSharks.Add(Instantiate(sharkManager.sharkPrefab, transform.position, Quaternion.identity)); // Instantiate the fish at that position and add it to the listy
                }

                sharkHealth.ModifyFood(reproductionCost); // How much food is removed upon reproduciton
                sharkHealth.timesReproduced++;

                GenerateNewGestationPeriod();
                currentSharkState = SharkState.Roaming; // Change state back to roaming

                canReproduce = false;
            }
        }
    }
 public void ChangeSharkState(SharkState to, GameObject reference = null)
 {
     switch(to){
     case SharkState.LOOK_AROUND:
         StartCoroutine("LookAround");
         break;
     case SharkState.ATTACK:
         StartCoroutine("Attack", reference);
         break;
     case SharkState.SWIM:
     case SharkState.START_SWIM:
         StartCoroutine("StartSwim");
         break;
     case SharkState.HIDE:
     case SharkState.START_HIDE:
         StartCoroutine("StopSwim");
         break;
     }
 }
Exemple #16
0
    protected virtual void PatrolState()
    {
        pf.FollowPath();

        timer -= Time.deltaTime;
        entity = vc.GetObjectInVisionCone(vc.locateRadius);

        if (timer < 0)
        {
            currentState = SharkState.ROAM;
            RoamStateStart();
        }

        if (entity != null)
        {
            currentState = SharkState.IN_SIGHT;
            InSightStateStart();
        }
    }
Exemple #17
0
    void UpdateState()
    {
        // SHARK FEEDING STATE SWITCH
        if (sharkHealth.currentFoodAmount <= (sharkHealth.initialFood / 100 * 66)) // Hungry when it loses 1/3 of it's food
        {
            currentSharkState = SharkState.Feeding;
            UpdateTargetToFeedOn();
        }

        else if (sharkHealth.currentFoodAmount > (sharkHealth.initialFood / 100 * 80)) // Shark will stop eating when it is at 80% of its original food, higher than 66% to provide a buffer
        {
            target            = sharkDestinationTarget;
            currentSharkState = SharkState.Roaming;
        }

        // SHARK REPRODUCTIVE STATE SWITCH
        if ((sharkHealth.currentFoodAmount >= (sharkHealth.initialFood / 100 * 50) || sharkHealth.currentFoodAmount > reproductionCost) &&
            currentSharkState != SharkState.Feeding &&
            canReproduce)
        {
            currentSharkState = SharkState.ReadyToReproduce;
        }
    }
Exemple #18
0
    protected virtual void RoamState()
    {
        pf.FollowPath();

        timer           -= Time.deltaTime;
        secondary_timer -= Time.deltaTime;

        entity = vc.GetObjectInVisionCone(vc.locateRadius);

        if (timer < 0)
        {
            currentState = SharkState.PATROL;
            PatrolStateStart(true);
        }

        if (secondary_timer < 0)
        {
            if (lastPathHeadTo)
            {
                pf.GenerateCirclePath((Vector2)(transform.position));
                lastPathHeadTo = false;
            }
            else
            {
                pf.GenerateHeadToPath((Vector2)(transform.position + transform.up * roamDistanceMultiplier));
                lastPathHeadTo = true;
            }
            secondary_timer = roamUpdatePathTime;
        }

        if (entity != null)
        {
            currentState = SharkState.IN_SIGHT;
            InSightStateStart();
        }
    }
Exemple #19
0
 public void Flee()
 {
     state = SharkState.FLEEING;
 }
Exemple #20
0
    // Update is called once per frame
    void Update()
    {
        switch (currentState)
        {
        case SharkState.CHARGING:
            chargeTimer -= Time.deltaTime;
            if (chargeTimer < 0.0f)
            {
                currentState = SharkState.RISING;
            }
            break;

        case SharkState.IDLE:
            Vector3 dir  = ((turtle.position + turtle.forward * 5.0f + Random.insideUnitSphere * 5.0f) - transform.position).normalized;
            float   dist = Vector3.Distance(transform.position, turtle.position);
            if (dist < 80.0f && cooldownTimer < 0.0f)
            {
                currentState  = SharkState.CHARGING;
                cooldownTimer = Random.Range(15.0f, 30.0f);
                targetVel     = dir * chargeSpeed;
                chargeTimer   = dist / chargeSpeed + 4.0f;
            }
            else
            {
                cooldownTimer -= Time.deltaTime;
                Vector3 xzdir = dir;
                xzdir.y   = 0.0f;
                xzdir     = xzdir.normalized;
                targetVel = (clockwise ? 1 : -1) * Vector3.Cross(dir, Vector3.up).normalized *idleSpeed + xzdir * Mathf.Lerp(-10f, 10f, dist / 100.0f) * idleSpeed / 3.0f;
            }
            break;

        case SharkState.RISING:
            targetVel = Vector3.up * idleSpeed;
            if (transform.position.y > 50f)
            {
                currentState = SharkState.IDLE;
                clockwise    = Random.value > 0.5f;
            }
            break;

        default:
            break;
        }
        if (currentState == SharkState.FEEDING)
        {
            feedingTime -= Time.deltaTime;
            if (feedingTime < 0.0f)
            {
                currentState = SharkState.IDLE;
            }
            if (!bloods.isPlaying)
            {
                bloods.Play();
            }
        }
        else
        {
            bloods.Stop();
        }
        body.velocity = Vector3.Lerp(body.velocity, targetVel, Time.deltaTime * 5.0f);
        //transform.rotation = Quaternion.LookRotation(body.velocity.normalized, Vector3.up);
        transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(body.velocity.normalized, Vector3.up), Time.deltaTime * 2.0f);
    }
Exemple #21
0
    // Update is called once per frame
    private void Update()
    {
        if (state == SharkState.RESTING && Vector3.Distance(player.transform.position, transform.position) < detection_distance)
        {
            state = SharkState.ROAMING;
            transform.GetChild(0).gameObject.SetActive(true);
        }
        else
        {
            switch (state)
            {
            case SharkState.ROAMING:

                if (Vector3.Distance(target, transform.position) < 1.0f)
                {
                    target = getRoamingTarget();
                }

                else if (Vector3.Distance(player.transform.position, transform.position) < hunting_distance && !player_script.hidden)
                {
                    state = SharkState.HUNTING;
                }


                else if (Vector3.Distance(player.transform.position, transform.position) > resting_distance)
                {
                    state = SharkState.RESTING;
                    transform.position = origin;
                    transform.GetChild(0).gameObject.SetActive(false);
                }

                break;

            case SharkState.HUNTING:

                target = player.transform.position;

                if (Vector3.Distance(target, transform.position) > hunting_distance || Vector3.Distance(transform.position, origin) > detection_distance || player_script.hidden)
                {
                    state  = SharkState.ROAMING;
                    target = transform.position;
                    return;
                }

                RaycastHit[] hits = Physics.RaycastAll(transform.position, target - transform.position, Mathf.Min(Vector3.Distance(target, transform.position), hunting_distance));

                bool found = false;
                for (int i = 0; i < hits.Length; i++)
                {
                    if (hits[i].collider.gameObject != gameObject && hits[i].collider.gameObject.tag != "Player")
                    {
                        found = false;
                        break;
                    }

                    else if (hits[i].collider.gameObject.tag == "Player")
                    {
                        found = true;
                    }
                }

                if (!found)
                {
                    state  = SharkState.ROAMING;
                    target = transform.position;
                }

                break;

            case SharkState.FLEEING:

                if (Vector3.Distance(player.transform.position, transform.position) > hunting_distance)
                {
                    state  = SharkState.ROAMING;
                    target = transform.position;
                }

                break;

            default:
                break;
            }
        }
    }
 public override void OnDeath()
 {
     Destroy(trigger);
     sharkState = SharkState.Death;
     DetermineState();
 }
 private IEnumerator LookAround()
 {
     currentState = SharkState.LOOK_AROUND;
     tr.position = lookAroundPosition;
     tr.rotation = lookAroundRotation;
     GameObject part = Instantiate(lookAroundParticles) as GameObject;
     //TODO: play sound here!
     SoundManager.instance.PlaySoundAt(audio, "SharkIntro");
     animation.Play("Look Around");
     part.transform.position = lookAroundPosition;
     yield return new WaitForSeconds(8f);
     Destroy(part);
     currentState = SharkState.HIDE;
     tr.position = hidePosition;
 }
    private IEnumerator StartSwim()
    {
        if(currentState == SharkState.START_HIDE){
            StopCoroutine("StopSwim");
        }
        currentState = SharkState.START_SWIM;
        animation.Play("Swim Around");
        tr.rotation = swimRotation;

        while(tr.position != swimPosition){
            tr.position = Vector3.MoveTowards(tr.position, swimPosition, swimSpeed*Time.deltaTime);
            yield return null;
        }
        currentState = SharkState.SWIM;
    }
 private IEnumerator StopSwim()
 {
     if(currentState == SharkState.START_SWIM){
         StopCoroutine("StartSwim");
     }
     currentState = SharkState.START_HIDE;
     while(tr.position != hidePosition){
         tr.position = Vector3.MoveTowards(tr.position, hidePosition, hideSpeed*Time.deltaTime);
         yield return null;
     }
     animation.Stop();
     currentState = SharkState.HIDE;
 }
 public void Hunt(GameObject prey)
 {
     m_Prey       = prey;
     m_SharkState = SharkState.Hunting;
 }
Exemple #27
0
 private void Awake()
 {
     currentSharkState = SharkState.Roaming;
     sharkHealth       = this.GetComponent <SharkHealth>();
 }
Exemple #28
0
    // Update is called once per frame
    void Update()
    {
        Debug.Log("Move : mSharkState " + mSharkState + " for " + tag);                 //+ " test_move_count" + test_move_count);
        //test_move_count++;
        if (mSharkState == SharkState.Pause)
        {
            //Dont move .
        }
        else if (mSharkState == SharkState.Move)
        {
            distance = Vector3.Distance(mSharkTarget, transform.position);
            if (distance <= 2f)
            {
                mSharkTarget = getSharkTarget();
            }

            /*	else if (shark_swim_radius_z - Mathf.Abs (transform.position.z) < 0){
             *      mSharkTarget.z = getSharkTargetZ ();
             * }
             * else if (shark_swim_radius_x - Mathf.Abs (transform.position.x) < 0){
             *      mSharkTarget.x = getSharkTargetX ();
             * }
             */
            Vector3 relativePos = mSharkTarget - transform.position;
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(relativePos), Time.deltaTime * angularVelocity);
            transform.Translate(Vector3.forward * Time.deltaTime * MobCurrentSpeed);
            if (my_wound_count > 0)
            {
                //mSharkState = SharkState.Attack;
                mSharkState = SharkState.JumpStart;
            }
        }
        else if (mSharkState == SharkState.Attack)
        {
            mSharkTarget = new Vector3(transform.position.x,
                                       waterSurfaceHeight,
                                       transform.position.z);
            Vector3 relativePos = mSharkTarget - transform.position;
            distance           = Vector3.Distance(mSharkTarget, transform.position);
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(relativePos), Time.deltaTime * angularVelocity * 5);
            // shark translate in forward direction.
            transform.Translate(Vector3.forward * Time.deltaTime * MobCurrentSpeed * 2);


            //Debug
            //mSharkState = SharkState.JumpStart;
            //end debug

            if (distance <= 5f)
            {
                mSharkState = SharkState.JumpStart;
            }
        }
        else if (mSharkState == SharkState.JumpStart)
        {
            mSharkTarget = new Vector3(ArcoreCamera.transform.position.x,
                                       ArcoreCamera.transform.position.y + 1f,
                                       ArcoreCamera.transform.position.z);
            distance = Vector3.Distance(mSharkTarget, transform.position);
            transform.Translate(Vector3.forward * Time.deltaTime * MobCurrentSpeed * 5);
            if (distance < 1f)
            {
                mSharkState = SharkState.Dead;
            }
        }
        else if (mSharkState == SharkState.Dead)
        {
            mSharkTarget = new Vector3(10f,
                                       waterSurfaceHeight,
                                       10f);

            transform.Translate(mSharkTarget);
            mSharkState    = SharkState.Move;
            my_wound_count = 0;
            health         = 100;
        }
    }
Exemple #29
0
    // Update is called once per frame
    void Update()
    {
        Debug.Log("Move : mSharkState " + mSharkState + " for " + tag);         //+ " test_move_count" + test_move_count);
        //test_move_count++;
        if (mSharkState == SharkState.Pause)
        {
            //Dont move .
        }
        else if (mSharkState == SharkState.Move)
        {
            distance = Vector3.Distance(mSharkTarget, transform.position);
            if (distance <= 2f)
            {
                mSharkTarget = getSharkTarget();
            }

            Vector3 relativePos = mSharkTarget - transform.position;
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(relativePos), Time.deltaTime * angularVelocity);
            transform.Translate(Vector3.forward * Time.deltaTime * MobCurrentSpeed);
            if (my_wound_count > 0)
            {
                //mSharkState = SharkState.Attack;
                mSharkState = SharkState.JumpStart;
            }
        }
        else if (mSharkState == SharkState.Attack)
        {
            mSharkTarget = new Vector3(ArcoreCamera.transform.position.x,
                                       waterSurfaceHeight,
                                       ArcoreCamera.transform.position.z);
            Vector3 relativePos = mSharkTarget - transform.position;
            distance           = Vector3.Distance(mSharkTarget, transform.position);
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(relativePos), Time.deltaTime * angularVelocity * 5);
            // shark translate in forward direction.
            transform.Translate(Vector3.forward * Time.deltaTime * MobCurrentSpeed * 2);


            //Debug
            //mSharkState = SharkState.JumpStart;
            //end debug

            if (distance <= 5f)
            {
                mSharkState = SharkState.JumpStart;
            }
        }
        else if (mSharkState == SharkState.JumpStart)
        {
            mSharkTarget = new Vector3(ArcoreCamera.transform.position.x,
                                       ArcoreCamera.transform.position.y + 1f,
                                       ArcoreCamera.transform.position.z);
            distance = Vector3.Distance(mSharkTarget, transform.position);
            transform.Translate(Vector3.forward * Time.deltaTime * MobCurrentSpeed * 5);
            if (distance <= 1f)
            {
                mSharkState = SharkState.Dead;
            }
        }
        else if (mSharkState == SharkState.Dead)
        {
            if (deadCount == 0)
            {
                //transform.Rotate(Vector3.forward * Time.deltaTime*4);
                transform.localRotation = Quaternion.AngleAxis(180, Vector3.forward);
            }
            if (deadCount > deadCountMax)
            {
                mSharkTarget = new Vector3(10f,
                                           waterSurfaceHeight,
                                           10f);

                transform.Translate(mSharkTarget);
                mSharkState    = SharkState.Move;
                my_wound_count = 0;
                health         = 100;
                deadCount      = 0;
            }
            deadCount++;
        }
    }
    public void Start()
    {
        instance = this;
        tr = transform;

        if(!audio)gameObject.AddComponent<AudioSource>();

        currentState = SharkState.SLEEPING;
        tr.position = hidePosition;
        players = new List<Transform>();
        animation.Stop();
        PauseGame.onFreezeGame += OnFreezeGameHandler;
    }