Пример #1
0
    public void MoveAgent(float[] act)
    {
        if (brain.brainParameters.vectorActionSpaceType == SpaceType.continuous)
        {
            //if (Mathf.Clamp(act[1], 0f, 1f) > 0.5f)
            //{
            //float movementAndle = RayPerception.DegreeToRadian((Mathf.Clamp(act[0], -1f, 1f) + 1f) * 180f);
            //m_Movement.SetDesiredMovementDirection(new Vector2(Mathf.Cos(movementAndle), Mathf.Sin(movementAndle)));
            //}
            //else
            //{
            //    m_Movement.SetDesiredMovementDirection(new Vector2(0, 0));
            //}

            m_Movement.SetMovementInputValue(Mathf.Clamp(act[0], -1f, 1f));
            m_Movement.SetTurnInputValue(Mathf.Clamp(act[1], -1f, 1f));

            Vector3 endPosition = transform.TransformDirection(RayPerception.PolarToCartesian(20f, Mathf.Clamp(act[2], 0f, 1f) * 180f));
            endPosition.y = 0;
            //float shootAndle = RayPerception.DegreeToRadian((Mathf.Clamp(act[2], -1f, 1f) + 1f) * 180f);
            //m_Shooting.SetDesiredFirePosition(new Vector3(10f * Mathf.Cos(shootAndle) + agentRB.position.x, 0, 10f * Mathf.Sin(shootAndle) + agentRB.position.z));
            m_Shooting.SetDesiredFirePosition(endPosition + agentRB.position);

            if (Mathf.Clamp(act[3], 0f, 1f) > 0.5f)
            {
                m_Shooting.SetFireIsHeld(true);
            }
            else
            {
                m_Shooting.SetFireIsHeld(false);
            }
        }
        else
        {
            switch ((int)act[0])
            {
            case 1:
                m_Movement.SetMovementInputValue(1);
                break;

            case 2:
                m_Movement.SetMovementInputValue(-1);
                break;

            case 3:
                m_Movement.SetTurnInputValue(1);
                break;

            case 4:
                m_Movement.SetTurnInputValue(-1);
                break;

            case 5:
                m_Shooting.SetDesiredFirePosition(transform.TransformDirection(RayPerception.PolarToCartesian(20f, 0f)) + agentRB.position);
                break;

            case 6:
                m_Shooting.SetDesiredFirePosition(transform.TransformDirection(RayPerception.PolarToCartesian(20f, 90f)) + agentRB.position);
                break;

            case 7:
                m_Shooting.SetDesiredFirePosition(transform.TransformDirection(RayPerception.PolarToCartesian(20f, 180f)) + agentRB.position);
                break;

            case 8:
                m_Shooting.SetFireIsHeld(true);
                break;

            case 9:
                m_Shooting.SetFireIsHeld(false);
                break;
            }
        }
    }