How to correct the scale when using Transform.TransformPoint

Let’s say we have a game object named gameObjectToClone with scale Vector3(0.001,0.001,0.001). Let’s say we also have a Vector3 named localPosition with the position Vector3(1,5,-3).

If we do: Vector3 worldPosition = gameObjectToClone.transform.TransformPoint (localPosition); the worldPosition will be almost the same because of such as small scale.

If we divide the worldPosition by the scale, it should give the position with the scale corrected. It seems it is not possible to divide doing Vector3 worldPositionScaled = worldPosition / scale;, so I also tried to multiply the worldPosition by 1 / scale. This multiplication is done with Vector3.Scale: Vector3 worldPositionScaled = Vector3.Scale(worldPosition, 1 / scale); Unfortunately it is not possible to perform a float / Vector3. Only Vector3 / float seems to be possible.

Is this approach correct? I guess I could divide x,y and z separately. But do you know any other approach? This one seems quite complex.

Just use Transform.TransformDirection lol

The supposition of “If we divide the worldPosition by the scale, it should give the position with the scale corrected” is not correct.

TransformPoint seems to multiply the given Vector3 position by the transform’s scale, and then adds the transform’s position. To understand it better let’s simplify watching only the y coordinate. Let’s say we have:


So imagine myGameObject.transform.y = 1, myVector3Position.y = 2, and myGameObject.transform.localScale = 0.001.

So TransformPosition would do before transforming to world space : 1 * 0.001 + 2. If afterwards we divide by 0.001, we would be doing something like(a) : 1 * 0.001 / 0.001 + 2 / 0.001 = 1 + 2 / 0.001 = 1.001. We don’t want that! We want something like 1 + 2 = 3. My solution is to set the localScale to 1 before calling TransformPosition. After calling TransformPosition, set the orinal scale back. It would be something like the following:

Vector3 tempOriginalScale = myGameObject.transform.localScale;
myGameObject.transform.localScale = 1;
myGameObject.transform.localScale = tempOriginalScale;

(a) → Notice it is only true if all the parent game objects (or the sum of all of them) are in the point 0,0,0 with rotation 0,0,0. However writing the example in the way I did I think can be more clear to understand the basic idea.

This will work: