예제 #1
0
 private void LateUpdate()
 {
     if (initialized)
     {
         if ((anchor.position - anchorPos).sqrMagnitude > 100)
         {
             ResetLinks();
         }
         else
         {
             float t = Time.deltaTime * targetFrameRate;
             transform.position = Vector3.Lerp(transform.position,
                                               flip ? lookAt - (position - lookAt) : position, t);
             lookAtLate = Vector3.Slerp(lookAtLate, lookAt, t);
             transform.LookAt(lookAtLate);
         }
         anchorPos = anchor.position;
         asteroidField?.UpdateBounds(lookAtLate);
     }
     else if (anchor.GetComponent <Rigidbody>().velocity.sqrMagnitude > Mathf.Epsilon)
     {
         Initialize();
     }
 }
예제 #2
0
    public override void CollectObservations()
    {
        Rigidbody rb = AgentPhysics.Rigidbody;

        // Measured max z is 48 with drag = 2, force multiplier = 2
        // Can be higher with AdvancedAgent's additional boost.
        scaledLocalVelocity = Localize(rb.velocity) * velocityScale;
        AddVectorObs(Util.Sigmoid(scaledLocalVelocity));
        // Measured max is 7 with angular drag = 5, torque multiplier = 1
        AddVectorObs(Util.Sigmoid(Localize(rb.angularVelocity) * 0.5f));

        Vector3 pos = transform.position;

        CastRays(pos);

        if (isBasic)
        {
            // Neutral values for initial training without opponents.
            AddVectorObs(0);            // detected agent (raycast)
            AddVectorObs(1);            // front opponent distance
            AddVectorObs(Vector2.zero); // front opponent direction
            AddVectorObs(Vector2.zero); // front opponent orientation
            AddVectorObs(Vector3.zero); // front opponent velocity
            AddVectorObs(1);            // has front opponent
            AddVectorObs(1);            // rear opponent distance
            AddVectorObs(Vector2.zero); // rear opponent direction
            AddVectorObs(Vector2.zero); // rear opponent orientation
            AddVectorObs(Vector3.zero); // rear opponent velocity

            // Reward forward speed.
            AddReward(scaledLocalVelocity.z * velocityRewardFactor);

            // One agent per asteroid field.
            asteroidField.UpdateBounds(pos);
        }
    }