Hi ! i get bad rotation values using the terrain data method called “ComputeDetailInstanceTransforms” which is supposed to return me the transform, including rotationY of my detail object in the terrain. attaching these values give me incoherent results, the detail object position is correct but the DetailInstanceTransform.rotationY value is mismatching what is used to render the detail object. Am i missing something ? I tried to adjust the rotation with a defined offset, but offsets in results are not identical, which makes me wondering what i’m doing wrong. Here is the code i used :
int detailPatchCount = terrain.terrainData.detailPatchCount;
for (int x = 0; x < detailPatchCount; x++)
{
for (int y = 0; y < detailPatchCount; y++)
{
DetailInstanceTransform[] detailsTransforms =
data.ComputeDetailInstanceTransforms(x, y, detailPrototype, 1, out Bounds bounds);
foreach (var dt in detailsTransforms)
{
DetailedObjectInstance dti = new();
dti.Prefab = data.detailPrototypes[detailPrototype].prototype;
dti.Position = new Vector3(dt.posX, dt.posY, dt.posZ);
dti.Rotation = new Vector3(0, dt.rotationY * Mathf.Rad2Deg, 0);
dti.RotationY = dt.rotationY;
dti.Scale = new Vector3(dt.scaleXZ, dt.scaleY, dt.scaleXZ);
dti.PrototypeIndex = detailPrototype;
output.Add(dti);
}
}
// Later... After getting detail instances data
// Instantiating a collider regarding the detail transform data
GameObject detailColliderGo = Instantiate(navColliderPrefab, t, true);
detailColliderGo.transform.position = detailInstance.Position;
detailColliderGo.transform.rotation = Quaternion.Euler(detailInstance.Rotation); // Incorrect rotation value
detailColliderGo.transform.localScale = detailInstance.Scale;
detailColliderGo.transform.name = detailInstance.Rotation.ToString() + " " + detailInstance.RotationY;
}