- Home /
Moving a transform behaves odd
Working on a 2D game.
So I have a Unit object prefab. The unit has a child object with a GUITexture (it's health bar)
I move the health bar guitexture if the unit moves like so:
public void LateUpdate () {
// if(!isSelected)
// return;
_lbl.SetActive(isSelected);
_pos = Camera.main.WorldToViewportPoint(transform.position);
_pos.z = 0f;
_pos.y = _pos.y+0.05f;
_lbl.transform.position = _pos;
}
The _lbl is the child object that contains the health bar.
When it was just a single object in the scene this worked perfectly. But whenever I instantiate a unit on runtime the health bar moves all jittery. Even if I drag a new object in the scene and save the scene the new object has the jitter. If i close unity and restart it and start the scene the new unit's health bar moves smooth again.
Since all units need to be dynamically instantiated this is a problem.
So to summarize:
Original object works like a charm, Object (clone) has weird jitter.
Any help with this conundrum would be greatly appreciated!
Your answer
Follow this Question
Related Questions
How can I get the x position for the left(and right) of the screen? 2 Answers
Dynamically Update Instantiated Objects Position 1 Answer
Offset Position 1 Answer
problem whit Instantiate Prefabs position. 0 Answers
Dropping an object behind player in respect to rotation,How to drop an object behind the player 1 Answer