GUIText and Velocity

Okay first off, you’re probably wondering how I’m relating those two and so the short version is that I’m in the process of making a so called “Tower Defense” game.

The longer version is this.

I am making a top-down “Tower Defense” game. I was thinking around on how to do a (for starters) simple health display above each AI unit. My first idea was a 3D text facing the camera. It worked well, except a couple nit-picks of my own.

The text faced the same way as the AI unit. (I later found a way to fix this, and could very well still go back to this.)

The text didn’t come in quite as clear as I’d have hoped.

So then, luckily, I came across the ObjectLabel script from here.
http://www.unifycommunity.com/wiki/index.php?title=ObjectLabel

This nifty little script (I’m using the Javascript version) solved both of the problems above.
But alas! With this script another, definitely more noticeable problem. And this is where the velocity part comes into play.

My AI units are using a Waypoint-based velocity powered (?) pathing system, shown here.

var waypoint : Transform[];
var speed : float = 20;
private var currentWaypoint : int;
private var loop : boolean = true;

function Update () {
	if (currentWaypoint < waypoint.length) {
		var target : Vector3 = waypoint[currentWaypoint].position;
		var moveDirection : Vector3 = target - transform.position;
		
		var velocity = rigidbody.velocity;
		
		if (moveDirection.magnitude < 1) {
			currentWaypoint++;
		}
		else {
			velocity = moveDirection.normalized * speed;
		}
	}
	else {
		if (loop == true){
			currentWaypoint = 0;
		}	
	}
	
	
	rigidbody.velocity = velocity;
	transform.LookAt(target);
}

The main problem now is this. Near and when the unit goes to change the next waypoint the GUI.Label shakes fiercely.

I’m assuming that it has to do with velocity seeing as how the majority of the code is taken up by velocity translations and it happens when the velocity direction goes to change.

My question (Yay finally!) is basically this: How would I go about getting the GUI.Label to stop shaking. I hope I explained it well enough that you grasp my meaning.

Are you using GUIText (which is what the ObjectLabel script appears to use), or GUI.Label()? If it’s the former, try changing Update() to LateUpdate() in the ObjectLabel script and see if that fixes the problem.

Oh, yes it’s GUIText. And I’ll try that suggestion soon.

Edit: It worked! I love that it’s a simple answer to that question. Thank you very much.