public override void AgentReset() { if (marathonSpawner == null) { marathonSpawner = GetComponent <MarathonSpawner>(); } Transform[] allChildren = GetComponentsInChildren <Transform>(); if (_hasValidModel) { // restore foreach (Transform child in allChildren) { if (child.gameObject.name.Contains("OpenAIHumanoid")) { continue; } //TODO child.position = transformsPosition[child.gameObject]; child.rotation = transformsRotation[child.gameObject]; var childRb = child.GetComponent <Rigidbody>(); if (childRb != null) { childRb.angularVelocity = Vector3.zero; childRb.velocity = Vector3.zero; } } marathonSpawner.ApplyRandom(); SetupMarathon(); UpdateQ(); beforeAngle = new float[MarathonJoints.Count]; curAngle = new float[MarathonJoints.Count]; return; } MarathonJoints = null; MarathonSensors = null; var rbs = this.GetComponentsInChildren <Rigidbody>().ToList(); foreach (var item in rbs) { if (item != null) { DestroyImmediate(item.gameObject); } } Resources.UnloadUnusedAssets(); marathonSpawner.SpawnFromXml(); allChildren = GetComponentsInChildren <Transform>(); transformsPosition = new Dictionary <GameObject, Vector3>(); transformsRotation = new Dictionary <GameObject, Quaternion>(); foreach (Transform child in allChildren) { transformsPosition[child.gameObject] = child.position; transformsRotation[child.gameObject] = child.rotation; } marathonSpawner.ApplyRandom(); //SetupMarathon(); UpdateQ(); _hasValidModel = true; recentVelocity = new List <float>(); beforeAngle = new float[MarathonJoints.Count]; curAngle = new float[MarathonJoints.Count]; }
public override void AgentReset() { if (DistanceTraveled != float.MinValue) { var scorer = FindObjectOfType <Scorer>(); scorer?.ReportScore(DistanceTraveled, "Distance Traveled"); } if (_spawnableEnv == null) { _spawnableEnv = GetComponentInParent <SpawnableEnv>(); } if (marathonSpawner == null) { marathonSpawner = GetComponent <MarathonSpawner>(); } mphBuffer = new List <Vector3>(); Transform[] allChildren = GetComponentsInChildren <Transform>(); if (_hasValidModel) { // restore foreach (Transform child in allChildren) { if (child.gameObject.name.Contains("OpenAIHumanoid")) { continue; } child.position = transformsPosition[child.gameObject]; child.rotation = transformsRotation[child.gameObject]; var childRb = child.GetComponent <Rigidbody>(); if (childRb != null) { childRb.angularVelocity = Vector3.zero; childRb.velocity = Vector3.zero; } } marathonSpawner?.ApplyRandom(); SetupMarathon(); UpdateQ(); return; } startPosition = transform.position; // HACK first spawned marathon agent should grab the camera var agentWithCamera = FindObjectsOfType <MarathonAgent>().FirstOrDefault(x => x.CameraTarget != null); if (agentWithCamera == null) { CameraTarget = FindObjectOfType <SmoothFollow>()?.gameObject; ShowMonitor = true; } MarathonJoints = null; MarathonSensors = null; var rbs = this.GetComponentsInChildren <Rigidbody>().ToList(); foreach (var item in rbs) { if (item != null) { DestroyImmediate(item.gameObject); } } Resources.UnloadUnusedAssets(); marathonSpawner?.SpawnFromXml(); allChildren = GetComponentsInChildren <Transform>(); transformsPosition = new Dictionary <GameObject, Vector3>(); transformsRotation = new Dictionary <GameObject, Quaternion>(); foreach (Transform child in allChildren) { transformsPosition[child.gameObject] = child.position; transformsRotation[child.gameObject] = child.rotation; } marathonSpawner?.ApplyRandom(); SetupMarathon(); UpdateQ(); _hasValidModel = true; recentVelocity = new List <float>(); }