I was trying to implement a feature which required transform.up
, the result didn't match the green axis gizmo displayed in the editor so I assumed it was being put off by the rotation of the object despite expecting the gizmo to adapt to that. I then modified the prefab such that everything was now child to an empty object and the secondary objects were child to that instead of the rotating model, and wrote a script that simply copies the transform so that it tracks. This still didn't show the values expected from what the gizmo in the editor showed. I then did a Debug.LogError
in the track script and this time the result was as expected.
Why is transform.up
showing the value expected from the local y-axis gizmo but when passing a reference to the original script and checking tracked.transform.up
gives off results?
To reproduce in a simpler environment I set up a simple test scene.
Simple default cube with the hierarchy structure shown in the screenshot. The transform values are as follows:
parent zeroed
x:0, y:-90, z:0 for cube
x:0, y:-90, z:90 for TrackPoint
Scripts are as follows:
test.cs - attached to trackpoint
private void Update()
{
Debug.LogError(transform.up);
}
Track.cs - attached to tracker
public Transform transformToTrack;
private void Update()
{
transform.position = transformToTrack.position;
transform.rotation = transformToTrack.rotation;
Debug.LogError(transform.up);
}
byref.cs - attached to cube
public GameObject refObj;
private void Update()
{
Debug.LogError(refObj.transform.up);
}
When run, if you clear the console then click pause you'll see that one of them differs from the others. I don't understand why. My project and this sample scene differ in which it is that is giving unexpected results but the results are inconsistent with what I would expect.
But wouldn't they all give the same result?