Exemplo n.º 1
0
        // Update is called once per frame
        void Update()
        {
            //GetComponent<Rigidbody>().velo
            if (Timer.time - lastEpisode > Consts.episodeTime * 2)
            {
                randomPos();
                lastEpisode = Timer.time;
            }
            float rayDistance = Consts.OutsideGroundLength * 0.8f;

            float[]      rayAngles         = { 90f };
            string[]     detectableObjects = { "obstacle" };
            List <float> buffer            = rayPer.Perceive(rayDistance, rayAngles, detectableObjects, 0f, 0f);

            movementTargetPosition = transform.position;
            if (Time.frameCount % 30 == 0)
            {
                randommove = EnemyController.GetRandomPosition();
            }
            //Debug.Log (name + randommove[0] + " " + randommove[1]);
            movementTargetPosition.x += randommove[0] * 10;
            movementTargetPosition.z += randommove[1] * 10;

            Vector3 deltaTarget = movementTargetPosition - transform.position;

            lookAtPos = transform.position + deltaTarget.normalized * 2.0f;
            rb.AddForce(deltaTarget.normalized * Consts.enemyMoveSpeed, ForceMode.VelocityChange);
            if (rb.velocity.magnitude > Consts.enemyMoveSpeed)
            {
                rb.velocity = rb.velocity.normalized * Consts.enemyMoveSpeed;
            }
        }
Exemplo n.º 2
0
        public override void CollectObservations()
        {
            float rayDistance = Consts.OutsideGroundLength * 0.8f;

            float[]      rayAngles         = { 20f, 90f, 160f, 45f, 135f, 70f, 110f };
            string[]     detectableObjects = { "obstacle", "wall", "agent", "target" };
            List <float> buffer            = rayPer.Perceive(rayDistance, rayAngles, detectableObjects, 0f, 0f);

            AddVectorObs(buffer);
            AddVectorObs(transform.forward.x);
            AddVectorObs(transform.forward.z);
        }