Exemple #1
0
    private void UpdateRays()
    {
        float distance    = Vector3.Distance(CurrentTarget.position, transform.position);
        float maxDistance = IAUtils.HypotenuseLength(GroundWidth, GroundHeight);

        rayHitGoal = false;

        RaycastHit hit;

        if (Physics.Linecast(transform.position, goal.position, out hit, goalDetectionMask))
        {
            lineRenderer.SetPosition(0, transform.position);
            lineRenderer.SetPosition(1, hit.point);
            lineRenderer.startColor = lineRenderer.endColor = Color.red;
            if (hit.transform == goal)
            {
                lineRenderer.startColor = lineRenderer.endColor = Color.green;
                rayHitGoal = true;
            }
        }

        targetLineRenderer.SetPosition(0, transform.position + Vector3.up);
        targetLineRenderer.SetPosition(1, CurrentTarget.position);
        targetLineRenderer.startColor = targetLineRenderer.endColor = targetGradient.Evaluate(Mathf.InverseLerp(0.0f, maxDistance, distance));
    }
Exemple #2
0
    public override void CollectObservations()
    {
        Vector3 goalRelativePosition   = transform.position.RelativePosition(goal.position);
        Vector3 switchRelativePosition = transform.position.RelativePosition(wallSwitch.transform.position);
        Vector3 positionOnGround       = ground.position.RelativePosition(transform.position);
        float   distanceToGoal         = Vector3.Distance(transform.position, goal.position);
        float   distanceToSwitch       = Vector3.Distance(transform.position, goal.position);

        float widthFactor    = 1.0f / GroundWidth;
        float heightFactor   = 1.0f / GroundHeight;
        float diagonalLength = IAUtils.HypotenuseLength(GroundWidth, GroundHeight);

        UpdateRays();

        float[] obs =
        {
            // Goal position
            goalRelativePosition.x *widthFactor,
            goalRelativePosition.z *heightFactor,

            // Switch position
            switchRelativePosition.x *widthFactor,
            switchRelativePosition.z *heightFactor,

            // Position on ground
            positionOnGround.x *widthFactor,
            positionOnGround.z *heightFactor,

            // Distance to goal
                distanceToGoal / diagonalLength,

            // Distance to switch
                distanceToSwitch / diagonalLength,

            // Can reach goal
                rayHitGoal ? 1 : 0,

            // Switch was triggered,
                wallSwitch.State == SwitchTrigger.SwitchState.ON ? 1 : 0,

            // Step count
            //(float) GetStepCount() / (float) agentParameters.maxStep
        };

        AddVectorObs(obs);
    }