Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

No actions being taken by this AI (MLAgents)

Discussion in 'ML-Agents' started by DIMUN999_sk, Nov 6, 2021.

  1. DIMUN999_sk

    DIMUN999_sk

    Joined:
    Sep 24, 2021
    Posts:
    3
    I have watched a tutorial how to setup this code, but the AI is not taking any decisions:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.MLAgents;
    5. using Unity.MLAgents.Sensors;
    6.  
    7.  
    8. public class TryMove : Agent
    9. {
    10.     [SerializeField] private float jumpForce;
    11.     [SerializeField] private KeyCode jumpKey;
    12.  
    13.     private Rigidbody rBody;
    14.     private Vector3 startingPosition;
    15.  
    16.     public override void Initialize()
    17.     {
    18.         rBody = GetComponent<Rigidbody>();
    19.         startingPosition = transform.position;
    20.     }
    21.  
    22.     public override void OnEpisodeBegin()
    23.     {
    24.         Reset();
    25.     }
    26.  
    27.     private void Jump()
    28.     {
    29.         rBody.AddForce(new Vector3(0, jumpForce, 0), ForceMode.VelocityChange);
    30.     }
    31.  
    32.     private void Reset()
    33.     {
    34.         transform.position = startingPosition;
    35.         rBody.velocity = Vector3.zero;
    36.  
    37.      
    38.     }
    39.  
    40.  
    41.     public override void OnActionReceived(float[] vectorAction)
    42.     {
    43.         Debug.Log(vectorAction.DiscreteActions[0]);
    44.  
    45.         if (Mathf.FloorToInt(vectorAction[0]) == 1)
    46.         {
    47.             Jump();
    48.         }
    49.          
    50.     }
    51.  
    52.     public override void CollectObservations(VectorSensor sensor)
    53.     {
    54.         sensor.AddObservation(transform.localPosition);
    55.     }
    56.  
    57.  
    58.  
    59.  
    60. }
    61.  
    Can someone please help me?
     
  2. gft-ai

    gft-ai

    Joined:
    Jan 12, 2021
    Posts:
    44
    Have you added decision requester component to the game object which this script is attached to?
     
  3. DIMUN999_sk

    DIMUN999_sk

    Joined:
    Sep 24, 2021
    Posts:
    3
    yes
     
  4. gft-ai

    gft-ai

    Joined:
    Jan 12, 2021
    Posts:
    44
    In the script i don’t see the value defined for the jumpForce variable, are you setting that somewhere?

    if that is not the case then have you tried manually making it jump with Heuristic method?
     
  5. DIMUN999_sk

    DIMUN999_sk

    Joined:
    Sep 24, 2021
    Posts:
    3
    its in SerializeField I edit in the inspector. it works with the heuristic metod
     
  6. gft-ai

    gft-ai

    Joined:
    Jan 12, 2021
    Posts:
    44