- Home /
How to attach line renderer point to same position on scaled objects
n my current game I have objects that are a set size, and depending on circumstances, these objects transforms are scaled in order to make the object appear bigger vs. providing a graphic for each size. This also helps save on memory.
I have a line renderer that is attached from one object and the other end of the line renderer is attached to the object I mentioned above.
The probably is, when the object is its regular size, the line renderer connects to the object at the right place, however, if I scale the object, the line renderer is no longer positioned correctly.
How can I make the line render always show on the same location of the game object even if it is scalled?
Answer by cjdev · Aug 22, 2015 at 05:13 AM
To keep the line renderer in the same relative position you want to have the point it's attached to also scale up in local coordinates when your objects scales. To do this you can make an empty GameObject and set it as a child of your object at the point where you want the line renderer to be attached. Then whenever you scale the transform of the parent object your child GameObject will move proportionately along with the object.
Note that the empty game object will also be scaled so I would only use the position information from it for the line renderer rather than attaching anything to it.