Differences

This shows you the differences between two versions of the page.

Link to this comparison view

unparentobjge [2017/05/24 14:27]
unparentobjge [2017/05/24 14:27] (current)
Line 1: Line 1:
 +====== How to unparent an object in GE. ======  ​
  
 +Game Version: ​ FS13 and later\\
 +GE Version: ​ ? and later
 +
 +----
 +
 +[[modding_tutorials|Modding Index]] | [[general_modding|General Modding Tutorials]]
 +
 +----
 +
 +===== Intro =====
 +
 +How to find out the actual world coordinates of an object in GE and remove a parent object while not disturbing the position of a child object.
 +
 +===== Prep Work =====
 +
 +
 +
 +===== Full Details =====
 +
 +Firstly, I am not a good wordsmith so apologies if this could be written better. It is written because of a particular mapping need I had and the answer wasn't so easy to find, I hope this can help someone in similar circumstances.
 +
 +[b]Problem:​[/​b]
 +You have an object or group which is several layers deep in scenegraph and you need to find out the actual world coordinates. You may want to remove a parent object and retain the exact world position of the child object. For this, you need to know the exact translation and rotation of the child object. In GE this is not so apparent.
 +An example of this would be when you have a long stretch of wall or fence that was created by nesting each panel on top of the previous one - and you need to remove one in the middle to make a gate without disturbing the others.
 +e.g.: you want to remove wall27 from the following: [wall01]->​[wall02]......[wall26]->​[wall27]->​[wall28]......[wall54]->​[wall55]..etc
 +
 +[b]Method:​[/​b]
 +In GE -
 +Select the object in question (the one you want to preserve, in this case [wall28]), note the Id in the the attributes panel. This will be an integer.
 +
 +Open the scripting panel - if it is not visible, use [Window]->​[Scripting] to see it.
 +
 +Enter the following where '​nnn'​ is the Id from above:
 +[code]print(getWorldTranslation(nnn));​[/​code]
 +Press [b][Shift]+[Enter][/​b] to execute the code.
 +The answer will appear in the format ​
 +[code](xx)x.xxxxxx(yy)y.yyyyyy(zz)z.zzzzzz[/​code] ​
 +It always contains 6 decimal places and does not separate the xyz values.
 +e.g.1 a result of "​-316.67288212.499066159.799332"​ means X= -316.6728821 Y= 2.499066 Z= 159.799332
 +e.g.2 a result of "​1020.21002295.338806-184.820007"​ means X= 1020.210022 Y= 95.338806 Z= -184.820007
 +
 +Now to get the rotation.
 +Enter the following where '​nnn'​ is the Id from above:
 +[code]print(getWorldRotation(nnn));​[/​code]
 +Press [b][Shift]+[Enter][/​b] to execute the code.
 +
 +The answer will appear in a similar format ​
 +[code](xx)x.xxxxxx(yy)y.yyyyyy(zz)z.zzzzzz [/code]
 +It always contains 6 decimal places and does not separate the xyz values. It is also in radians as opposed to the values that you see in the attributes panel which are in degrees.
 +
 +e.g. a result of "​0.000000-1.5707960.000000"​ means X= 0.000000 Y= -1.570796 Z= 0.000000
 +
 +The only thing left to do is convert the radians value to degrees. You can do this with any scientific calculator or by using the formula 1 rad = 180º/π.
 +The handiest way is to use google - search for [url="​http://​www.google.com/#​q=-1.570796+radians+to+degrees"​]"​-1.570796 radians to degrees"​[/​url] and the result is -89.9999813 degrees *in the case above, the item was set to -90deg in attributes).
 +
 +Now, cut and paste the object - [wall28] back to a root node or any node where there are no translations. Apply the rotations and translations you got from above and viola, it will be in the *exact* same position and orientation. You can now delete [wall27] to make way for your gate.
 +
 +
 +----
 +
 +Original Author: ​ SteveC | Date:  March 17, 2015
 +        ​
 +[[modding_tutorials|Modding Index]] | [[general_modding|General Modding Tutorials]]