예제 #1
0
    /// <summary>
    /// set translate, rotate and distance travelled
    /// </summary>
    void FixedUpdate()
    {
        if (!alive)
        {
            return;
        }

        float h = 0;
        float v = dna.GetGene(0);

        if (seeWall)
        {
            h = dna.GetGene(1);
        }

        transform.Translate(0, 0, v * 0.001f);
        transform.Rotate(0, h, 0);
        distanceTravelled = Vector3.Distance(startPosition, transform.position);
    }
예제 #2
0
    /// <summary>
    /// Set value via bool fields and calculate direction
    /// </summary>
    void FixedUpdate()
    {
        if (!alive)
        {
            return;
        }

        // read DNA
        float h = 0;
        float v = 1.0f; //dna.GetGene(0);

        if (seeUpWall)
        {
            h = dna.GetGene(0);
        }
        else if (seeDownWall)
        {
            h = dna.GetGene(1);
        }
        else if (seeTop)
        {
            h = dna.GetGene(2);
        }
        else if (seeBottom)
        {
            h = dna.GetGene(3);
        }
        else
        {
            h = dna.GetGene(4);
        }

        rb.AddForce(transform.right * v);
        rb.AddForce(transform.up * h * 0.1f);
        distanceTravelled = Vector3.Distance(startPosition, transform.position);
    }
예제 #3
0
    // FixedUpdate is called in sync with physics.
    private void FixedUpdate()
    {
        // Read DNA
        float horizontal  = 0f;
        float vertical    = 0f;
        bool  isCrouching = false;

        if (Dna.GetGene(0) == 0)
        {
            vertical = 1;
        }
        else if (Dna.GetGene(0) == 1)
        {
            vertical = -1;
        }
        else if (Dna.GetGene(0) == 2)
        {
            horizontal = -1;
        }
        else if (Dna.GetGene(0) == 3)
        {
            horizontal = 1;
        }
        else if (Dna.GetGene(0) == 4)
        {
            isJumping = true;
        }
        else if (Dna.GetGene(0) == 5)
        {
            isCrouching = true;
        }

        moveDirection = vertical * Vector3.forward + horizontal * Vector3.right;
        thirdPersonCharacter.Move(moveDirection, isCrouching, isJumping);
        isJumping = false;

        if (isAlive)
        {
            TimeAlive        += Time.deltaTime;
            DistanceTravelled = Vector3.Magnitude(this.transform.position - startPosition);
            Debug.Log(DistanceTravelled);
        }
    }
예제 #4
0
파일: Brain.cs 프로젝트: vanavski/ML-Unity
    /// <summary>
    /// Choose direction by gen value
    /// </summary>
    public void FixedUpdate()
    {
        float h      = 0;
        float v      = 0;
        bool  crouch = false;

        switch (dna.GetGene(0))
        {
        case 0: v = 1;
            break;

        case 1: v = -1;
            break;

        case 2:
            h = -1;
            break;

        case 3:
            h = 1;
            break;

        case 4:
            jump = true;
            break;

        case 5:
            crouch = true;
            break;
        }

        move = v * Vector3.forward + h * Vector3.right;
        mCharacter.Move(move, crouch, jump);
        jump = false;
        if (alive)
        {
            timeAlive += Time.deltaTime;
        }
    }
예제 #5
0
    // Update is called once per frame
    void Update()
    {
        if (!alive)
        {
            return;
        }

        Debug.DrawRay(eyes.transform.position, eyes.transform.forward * 10, Color.red, 10);
        seeGround = false;
        RaycastHit hit;

        if (Physics.Raycast(eyes.transform.position, eyes.transform.forward * 10, out hit))
        {
            if (hit.collider.gameObject.tag == "platform")
            {
                seeGround = true;
            }
        }
        timeAlive = WalkerPM.elapsed;

        float turn = 0;
        float move = 0;

        if (seeGround)
        {
            if (dna.GetGene(0) == 0)
            {
                move = 1;
                timeWalking++;
            }
            else if (dna.GetGene(0) == 1)
            {
                turn = -90;
            }
            else if (dna.GetGene(0) == 2)
            {
                turn = 90;
            }

            //switch (dna.GetGene(0))
            //{
            //    case 0: move = 1;
            //        break;
            //    case 1: turn = -90;
            //        break;
            //    case 2: turn = 90;
            //        break;
            //}
        }
        else
        {
            if (dna.GetGene(1) == 0)
            {
                move = 1;
                timeWalking++;
            }
            else if (dna.GetGene(1) == 1)
            {
                turn = -90;
            }
            else if (dna.GetGene(1) == 2)
            {
                turn = 90;
            }

            //switch (dna.GetGene(1))
            //{
            //    case 0: move = 1;
            //        break;
            //    case 1: turn = -90;
            //        break;
            //    case 2: turn = 90;
            //        break;
            //}
        }

        transform.Translate(0, 0, move * 0.1f);
        transform.Rotate(0, turn, 0);
    }