コード例 #1
0
    // debug parameters
    //private MeshRenderer meshRenderer;

    // update timers
    //private float stateUpdateInterval = .5f;
    //private float stateTimer;

    void Start()
    {
        // GameManager
        GM = FindObjectOfType <GameManager>();

        // interaction squared
        fenceRepulsion2  = fenceRepulsion * fenceRepulsion;
        minFenceBoundary = Mathf.CeilToInt(fenceRepulsion / GM.binSize);
        maxFenceBoundary = GM.precision - minFenceBoundary;

        // get mesh renderer for debug coloring purposes
        //meshRenderer = GetComponentInChildren<MeshRenderer>();
        //meshRenderer.material.color = new Color(1.0f, 1.0f, .0f);

        // random state
        sheepState = (Enums.SheepState)Random.Range(0, 3);

        // speed
        SetSpeed();
        desiredV = v;

        // random heading
        float theta = Random.Range(-Mathf.PI, Mathf.PI);

        transform.forward = new Vector3(Mathf.Cos(theta), .0f, Mathf.Sin(theta)).normalized;
        desiredTheta      = transform.forward;

        // timer
        //stateTimer = Random.Range(.0f, stateUpdateInterval);

#if !CAPSULE
        Color cottonColor = Color.white;

        // Assign random collor to fur
        if (Random.value < .05f)
        {
            float blackShade = Random.Range(0.2f, 0.3f);
            cottonColor = new Color(blackShade, blackShade, blackShade, 1.0f);
        }
        else
        {
            float grayShade = Random.Range(0.7f, .9f);
            cottonColor = new Color(grayShade, grayShade, grayShade, 1.0f);
        }

        foreach (Renderer fur in sheepCottonParts)
        {
            if (fur.materials.Length < 2)
            {
                fur.material.color = cottonColor;
            }
            else
            {
                fur.materials[1].color = cottonColor;
            }
        }
#endif
    }
コード例 #2
0
    void UpdateState()
    {
        // test states
        float random = .0f;

        // first test the transition between idle and walking and viceversa
        if (sheepState == Enums.SheepState.Idle)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < currentCell.p_iw)
            {
                sheepState = Enums.SheepState.Walking;
            }
        }
        else if (sheepState == Enums.SheepState.Walking)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < currentCell.p_wi)
            {
                sheepState = Enums.SheepState.Idle;
            }
        }

        // second test the transition to running
        // which has the same rate regardless if you start from walking or idle
        if (sheepState == Enums.SheepState.Idle || sheepState == Enums.SheepState.Walking)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < currentCell.p_iwr)
            {
                sheepState = Enums.SheepState.Running;
            }
        }
        // while testing the transition to running also test the transition from running to standing
        else if (sheepState == Enums.SheepState.Running)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < currentCell.p_ri)
            {
                sheepState = Enums.SheepState.Idle;
            }
        }

        SetSpeed();
    }
コード例 #3
0
    void UpdateState()
    {
        // refresh numbers of neighbours
        NeighboursUpdate();

        // probabilities
        p_iw = (1 + alpha * n_walking) / tau_iw;
        p_iw = 1 - Mathf.Exp(-p_iw);

        p_wi = (1 + alpha * n_idle) / tau_wi;
        p_wi = 1 - Mathf.Exp(-p_wi);

        p_iwr = .0f;
        p_ri  = .0f;

        if (l_i > .0f)
        {
            p_iwr = (1 / tau_iwr) * Mathf.Pow((l_i / d_R) * (1 + alpha * m_running), delta);
            p_iwr = 1 - Mathf.Exp(-p_iwr);
            p_ri  = (1 / tau_ri) * Mathf.Pow((d_S / l_i) * (1 + alpha * m_idle), delta);
            p_ri  = 1 - Mathf.Exp(-p_ri);
        }

        // test states
        float random = .0f;

        // first test the transition between idle and walking and viceversa
        if (sheepState == Enums.SheepState.Idle)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < p_iw)
            {
                sheepState = Enums.SheepState.Walking;
            }
        }
        else if (sheepState == Enums.SheepState.Walking)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < p_wi)
            {
                sheepState = Enums.SheepState.Idle;
            }
        }

        // second test the transition to running
        // which has the same rate regardless if you start from walking or idle
        if (sheepState == Enums.SheepState.Idle || sheepState == Enums.SheepState.Walking)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < p_iwr)
            {
                sheepState = Enums.SheepState.Running;
            }
        }
        // while testing the transition to running also test the transition from running to standing
        else if (sheepState == Enums.SheepState.Running)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < p_ri)
            {
                sheepState = Enums.SheepState.Idle;
            }
        }

        SetSpeed();
    }
コード例 #4
0
    void UpdateState()
    {
        previousSheepState = sheepState;

        // calculate local probabilities
        // transition parameters
        n_idle    = 0;
        n_walking = 0;

        // always separate from metric neighbours
        foreach (HybridController neighbour in currentCell.hcList)
        {
            if (neighbour.id == id)
            {
                continue;               // exclude self from count
            }
            Vector3 offset = transform.position - neighbour.transform.position;

            if (offset.sqrMagnitude < GM.r_o2)
            {
                // state counter
                switch (neighbour.sheepState)
                {
                // idle metric neighbours
                case Enums.SheepState.Idle:
                    n_idle++;
                    break;

                // walking metric neighbours
                case Enums.SheepState.Walking:
                    n_walking++;
                    break;
                }
            }
        }

        // idle -> walking
        p_iw = (1 + alpha * n_walking) / tau_iw;
        p_iw = 1 - Mathf.Exp(-p_iw);

        // walking -> idle
        p_wi = (1 + alpha * n_idle) / tau_wi;
        p_wi = 1 - Mathf.Exp(-p_wi);

        // idle/walking -> running
        p_iwr = Mathf.Exp(HM.area - (A_r * GM.nOfSheep)) * (1 + (alpha * HM.m_torunning));
        p_iwr = 1 - Mathf.Exp(-p_iwr);

        // dist to centre of mas
        float distToCom = (HM.com - transform.position).sqrMagnitude;

        // running -> idle
        p_ri = (1 / Mathf.Exp(distToCom - (d_s * GM.nOfSheep))) * (1 + (alpha * HM.m_toidle));
        p_ri = 1 - Mathf.Exp(-p_ri);

        // test states
        float random = .0f;

        // first test the transition between idle and walking and viceversa
        if (sheepState == Enums.SheepState.Idle)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < p_iw)
            {
                // change state to walking and update speed
                sheepState = Enums.SheepState.Walking;
                desiredV   = GM.v_1;
            }
        }
        else if (sheepState == Enums.SheepState.Walking)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < p_wi)
            {
                // change state to idle and update speed
                sheepState = Enums.SheepState.Idle;
                desiredV   = .0f;
            }
        }

        // second test the transition to running
        // which has the same rate regardless if you start from walking or idle
        if (sheepState == Enums.SheepState.Idle || sheepState == Enums.SheepState.Walking)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < p_iwr)
            {
                // change state to running and update speed
                sheepState = Enums.SheepState.Running;
                desiredV   = GM.v_2;
            }
        }
        // test the transition from running to standing
        else if (sheepState == Enums.SheepState.Running)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < p_ri)
            {
                // change state to idle and update speed
                sheepState = Enums.SheepState.Idle;
                desiredV   = .0f;
            }
        }
    }
コード例 #5
0
    void UpdateState()
    {
        previousSheepState = sheepState;

        // refresh numbers of neighbours
        NeighboursUpdate();

        // idle -> walking
        p_iw = (1 + alpha * n_walking) / tau_iw;
        p_iw = 1 - Mathf.Exp(-p_iw * dT);

        // walking -> idle
        p_wi = (1 + alpha * n_idle) / tau_wi;
        p_wi = 1 - Mathf.Exp(-p_wi * dT);

        p_iwr = .0f;
        p_ri  = .0f;
        if (l_i > .0f)
        {
            // idle/walking -> running
            p_iwr = (1 / tau_iwr) * Mathf.Pow((l_i / d_R) * (1 + alpha * m_running), delta);
            p_iwr = 1 - Mathf.Exp(-p_iwr * dT);

            // running -> idle
            p_ri = (1 / tau_ri) * Mathf.Pow((d_S / l_i) * (1 + alpha * m_toidle), delta);
            p_ri = 1 - Mathf.Exp(-p_ri * dT);
        }

        // test states
        float random = .0f;

        // first test the transition between idle and walking and viceversa
        if (sheepState == Enums.SheepState.Idle)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < p_iw)
            {
                // change state to walking and update speed
                sheepState = Enums.SheepState.Walking;
                desiredV   = GM.v_1;
            }
        }
        else if (sheepState == Enums.SheepState.Walking)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < p_wi)
            {
                // change state to idle and update speed
                sheepState = Enums.SheepState.Idle;
                desiredV   = .0f;
            }
        }
        // second test the transition to running
        // which has the same rate regardless if you start from walking or idle
        if (sheepState == Enums.SheepState.Idle || sheepState == Enums.SheepState.Walking)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < p_iwr)
            {
                // change state to running and update speed
                sheepState = Enums.SheepState.Running;
                desiredV   = GM.v_2;
            }
        }
        // test the transition from running to standing
        else if (sheepState == Enums.SheepState.Running)
        {
            random = Random.Range(.0f, 1.0f);
            if (random < p_ri)
            {
                // change state to idle and update speed
                sheepState = Enums.SheepState.Idle;
                desiredV   = .0f;
            }
        }
    }