(Hope this is the right forum…)
Summary: I have an articulated body (AB) that I reposition using TeleportRoot on the root object. I am repositioning it to its current location and orientation (‘why’ is described below) and the root body rotates considerably and the child ABs get grossly reoriented. I do not think they should.
Description: I built a four-legged spider using ABs. It functions as intended when operating manually. I want to apply AI training to it, so will need to reset the spider to its original position, etc. in the ML-Agents’ associated OnEpisodeBegin. Because there appeared to be a problem with TeleportRoot to reposition the spider, I prepared a simple test scenario to illustrate the issue.
The initial transform for the spider:

I start the game and while it is starting up, I press Pause so it will pause after the first frame is displayed:

The relevant code:
using System.Collections.Generic;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
public class SpiderAgent : Agent
{
[System.Serializable]
public struct Joint
{
public GameObject jointGO;
}
public Joint[ ] articulatedJoint;
public Transform target;
public float hip_fr = 0.5f;
public float hip_ud = 0.0f;
public float knee_ud = 0.945f;
// Initialize the agent
public override void Initialize()
{
GameObject go;
ArticulationBody ab;
JointController jc;
print(“Initialize begins”);
// relocate to origin, realign with axes, and reposition legs
ab = GetComponent();
ab.TeleportRoot(new Vector3(0.0f, 10.0f, 0.0f), Quaternion.identity);
ab.velocity = Vector3.zero;
ab.angularVelocity = Vector3.zero;
for (int i = 0; i < articulatedJoint.Length; i++) // 1st joint is Hip, 2nd is Knee
{
go = articulatedJoint*.jointGO;*
jc = go.GetComponent();
jc.FwdRev = hip_fr;
jc.UpDown = hip_ud;
i++;
go = articulatedJoint*.jointGO;*
jc = go.GetComponent();
jc.FwdRev = 0.0f;
jc.UpDown = knee_ud;
}
}
// Reset the agent when an episode begins
public override void OnEpisodeBegin()
{
return;
…
In this particular example, the child ABs are originally orientated properly. The translation of the root body should (IMO) keep the root and child AB orientations the same. This clearly doesn’t happen and the flailing legs is a particular problem.
I am using Unity 2020.3.21f1 (although I have tried it also with slightly older versions and with 2021.1.26f1 just in case something really new fixes the issue) on Windows 10 Home 64-bit. I also have ML-Agents 1.0.8 (aka release 18).
Here is the object hierarchy (RaysForward and Target are for eventual AI training and running):
