How to prevent child GameObject from rotating when it's parent rotates?
In my game I have a health bar above the units (ships). I'm using Orthographic camera, when the ship is moving and rotating the health bar turns 'away' from the camera.
I've seen some similar questions and all the answers there suggest to simply rotate the health bar along with it's parent on every Update()
or LateUpdate()
. It works, but it seems terribly inefficient, especially since I'm making a mobile game and there are multiple units.
Is there any way to make child gameobjects rotation fixed?
Answer by hexagonius · Jan 03, 2017 at 08:36 PM
no chance, it's one of 3 (the others are scale and position) functions of childing. using Update is correct, but I would not child it bit use the parent as a target it follows with an upwards offset. this way you have full control over how large it should be, scale with it or not, rotate or not...
That's an interesting idea. You think something like Vector3.$$anonymous$$oveTowards
would be more efficient?
it's really not that inefficient and there's not really another way to do this. just update the position every Update and everything is find, just don't child it.