- Home /
[C#] TransformPoint only works at 0,0,0 world location
This might be a bit hard to emplane, but i will try my best.
I got a gameobject This gameobject is called gameobject1, and its world location is 0,0,0 And it contains a script that has a list of points for this example the list will contain 4 points, Those 4 points are set at its local space at (-0.25, -0.25, 0) (-0.25, 0.25, 0) (0.25, -0.25, 0) (0.25, 0.25, 0)
Gameobject1 looks like this:
I now make a copy of that gameobject and i call it gameobject2 And its world location is 1,0,0 it to got a list of points just like the other gameobject, it to looks like: (-0.25, -0.25, 0) (-0.25, 0.25, 0) (0.25, -0.25, 0) (0.25, 0.25, 0)
Now i want to add all the points from gameobject2, to gameobject1.
I can do that by saying somthing like:
gameobject1.points.AddRange( gameobject2.points );
However this will result in that the gameobject2 points will be placed right on top the gameobjects1 points, its ignoring the fact that gameobject2 is not at 0,0,0 but at 1,0,0 world location.
But i can fix that by using gameobject2.transform.TransformPoint And this works just fine.
This will give me gameobject1 with all the points of gameobject1 and gameobject2. And that will look like this:
But this only seems to work if gameobject1 world location is at 0,0,0. Once i change the gameobject1 location to for example 0,1,0 and gameobject2's world location to 1,1,0 The the points will be not next to it where you expect it to be but 1 extra up.
And that will look like:
And at this point i have tried many things and im not one to ask questions before googling, but i think after about 3 weeks thinks about it its time to ask.
ow right, sorry if there are no spaces in the question and its all 1 big messup post, i could not find out how to do a new line :/ why enter not just work like enter works i dont know :/
What's your exact code now? Since all points are given in local space you have to transform all of them into worldspace, though the points of GO1 with the transform of GO1 and the points of GO2 with the transform of GO2.
Please provide code to show precisely what you are doing. TransformPoint indeed does work correctly so I think the issue is that in your code what you think you are doing and what you are actually doing are perhaps not the same thing.
Answer by imtehQ · Apr 19, 2018 at 08:26 AM
I solved the issue by creating the points one by one like:
(Gameobject2.tranform.position - Gameobject.tranform.position) + point[i]
This will always place the points correctly
Your answer
Follow this Question
Related Questions
Unity UI Text - Always show 5 last lines 0 Answers
Landscape app goes portrait during app store login 0 Answers
How can I disable my player movement and camera movement when I hit I to open my inventory? 2 Answers
Can anyone tell me what is this building to the assets folder is not allowed.. 2 Answers
How can i do a Very basic enemy AI or chase system? Unity 5 1 Answer