I have copied my TrainingArea many times, and while training, it seems to me that when…
- User
I have copied my TrainingArea many times, and while training, it seems to me that when other agents eat their food, it disappears from the first agent. I may be wrong and it may not be. But I know for sure that the food disappears by itself from the very first agent.
here's my TrainingArea.cs: using UnityEngine; using System.Collections.Generic;
public class TrainingArea : MonoBehaviour { [SerializeField] private GameObject playerPrefab; [SerializeField] private GameObject foodPrefab; [SerializeField] private int numberOfFoods = 10; [SerializeField] private float spawnRadius = 5.0f; private PlayerAgent playerAgent; private List foodInstances = new List();
private void Start() { SpawnPlayer(); SpawnFoods(); } public void ResetArea() { ResetPlayer(); ResetFoods(); } private void ResetPlayer() { if (playerAgent != null) { playerAgent.transform.localPosition = new Vector3(Random.Range(-spawnRadius, spawnRadius), Random.Range(-spawnRadius, spawnRadius), 0); } } public void ResetFoods() { List<GameObject> eatenFoods = new List<GameObject>(); foreach (GameObject food in foodInstances) { if (food != null) { food.transform.localPosition = GetValidSpawnPosition(); } else { eatenFoods.Add(food); } } foreach (GameObject food in eatenFoods) { Vector3 spawnPosition = GetValidSpawnPosition(); GameObject foodInstance = Instantiate(foodPrefab, spawnPosition, Quaternion.identity, transform); foodInstances.Add(foodInstance); } // Remove eaten food references from the list foodInstances.RemoveAll(food => food == null); } private void SpawnPlayer() { Vector3 randomPosition = GetValidSpawnPosition(); GameObject playerInstance = Instantiate(playerPrefab, randomPosition + transform.position, Quaternion.identity, transform); playerAgent = playerInstance.GetComponent<PlayerAgent>(); } private void SpawnFoods() { for (int i = 0; i < numberOfFoods; i++) { Vector3 spawnPosition = GetValidSpawnPosition(); GameObject foodInstance = Instantiate(foodPrefab, spawnPosition, Quaternion.identity, transform); foodInstances.Add(foodInstance); } } private Vector3 GetValidSpawnPosition() { Vector3 spawnPosition; do { spawnPosition = new Vector3(Random.Range(-spawnRadius, spawnRadius), Random.Range(-spawnRadius, spawnRadius), 0); } while (playerAgent != null && Vector3.Distance(playerAgent.transform.localPosition, spawnPosition) <= 5.0f); return spawnPosition; } public bool AllFoodEaten() { foreach (GameObject food in foodInstances) { if (food != null) { return false; } } return true; }}
here's my PlayerAgent.cs: using UnityEngine; using Unity.MLAgents; using Unity.MLAgents.Actuators; using Unity.MLAgents.Sensors;
public class PlayerAgent : Agent { [SerializeField] private float moveSpeed = 5.0f; [SerializeField] private float maxEpisodeTime = 20.0f; private TrainingArea trainingArea; private float episodeTime = 0.0f;
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.