- Home /
transform.transformpoint not returning correct value
Like the title says, transform.transformpoint isn't returning the correct value. For some values of the variable point, it's off by a little, some it's off by a lot.
foreach (PolygonCollider2D col in colliders)
{
foreach (Vector2 point in col.points)
{
Vector2 worldPoint = col.transform.TransformPoint(point);
allCorners[index] = worldPoint;
index++;
}
}
Don't worry about the other variables and such, the variable worldPoint returns incorrectly.
Answer by Bunny83 · Sep 20, 2019 at 12:20 AM
Are you sure you did not rotate the gameobjects around x or y? Also you did not have the sceneview camera rotated at an angle? do you work in 2d mode? What exactly do you do with those worldspace positions? Keep in mind that TransformPoint still returns a Vector3 and you just ignore the z value. If there are some rotations involved the positions would be off. Do you have any screenshots? Have you tried debugging the actual 3d coordinates returned by TransformPoint?
The gameobject is not rotated. The camera is not rotated and I am working in 2D. I am trying to deter$$anonymous$$e the world position of the points of a polygon collider.
The world position of that corner is the target Vector, however the position of the gizmo is what's returned. I used an empty gamobject moved to the position of"worldPoint".
I've even tried testing the world position of a single vertex in the start function with transformPoint, and it still doesn't work. The object that is being tested is a basic rectangle of dimensions 6x2.5.
Your answer
![](https://koobas.hobune.stream/wayback/20220612212404im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
World Coordinates of BoxCollider2D ? 1 Answer
Comparing World Positions 1 Answer
Gross "Almost zero" Vector components when adjusting to local space and custom handles 2 Answers
Can someone please explain the difference between TransformPoint and InverseTransformPoint? 1 Answer
Show points text on collision 0 Answers