Having trouble doing power bar..

Hello there, have a few question here.

Im trying to do a power bar for my game. manage to do it but having a bit of a bug. Dont know why, cannot find any error.
here’s a sample of what im doing ;
https://dl.dropbox.com/u/61560159/AirBalloon/Balloon/Balloon.html

So as you can see, my power bar does decrees in time but it jitter badly. not sure why, and if you collect the pick up my power bar will not fill up to the top, below here i provide my script:

#pragma strict

public var gasObject : Transform;
public var gasStart : Transform;
public var gasEnd : Transform;

public var totalDistance : float;
public var gasDistance : float;
public var gasProgress : float;

public var t : float;
public var gasCurrent : float;
public var gasAmount : float;
public var gasUsed : boolean;

public var player : PlayerController;

function Start ()
{
	gasCurrent = gasAmount;
}

function Update ()
{
	gas ();
	dropGas ();
}

function gas ()
{
	if (gasUsed)
	{
		if (player.ySpeed > 0.1)
		{
			//if player have speedY the fuel will be burn//
			gasCurrent -= Time.deltaTime;
		}
		
		if (gasCurrent >= gasAmount)
		{
			gasCurrent = gasAmount;
		}
		else if (gasCurrent <= 0)
		{
			gasCurrent = 0;
		}
	}
}

function dropGas ()
{
	totalDistance = gasEnd.position.y - gasStart.position.y;
	gasDistance = gasObject.position.y - gasStart.position.y;
	gasProgress = gasDistance / totalDistance;
	
	gasProgress = gasCurrent;
	t = Time.deltaTime * 100 / gasProgress;
	gasObject.position = Vector3.Lerp (gasStart.position, gasEnd.position, t);
}

solved it, need to change my Time.deltaTime to Time.fixedDeltaTime. no more jitter. but having another problem. how do i set my “gasCurrent” and “gasProgress” to sync when decreasing?

for example, if I put my “gasCurrent” = 10, I want my “gasProgress” to sync with the “gasCurrent” amount. I would like to tell my power bar that “gasCurrent” = 10 is equal to “gasProgress” = 100%.

so if I change my “gasCurrent” it will still read as a 100% value.

bump

Maybe set a max gas amount? So:

gasProgress = (gasCurrent/maxGas) * 100;

I have set my “max gas amount”

if (gasCurrent >= gasAmount)
		{
			gasCurrent = gasAmount;
		}
		else if (gasCurrent <= 0)
		{
			gasCurrent = 0;
		}

Okay for the percentage problem, I manage to do it like this, not sure its the right way or not but here it is:

function dropGas ()
{
	//gasProgress = gasCurrent;
	//t = Time.fixedDeltaTime / gasProgress * 100;
	
	//gasProgress = (gasCurrent / gasAmount) * 100;
	//t = (Time.fixedDeltaTime / gasProgress) * 1000;
	
	totalDistance = gasEnd.position.y - gasStart.position.y;
	gasDistance = gasObject.position.y - gasStart.position.y;
	gasProgress = gasDistance / totalDistance;
	
	gasProgress = (gasCurrent / gasAmount) * 100;
	t = (Time.fixedDeltaTime / gasProgress) * 1000;
	gasObject.position = Vector3.Lerp (gasStart.position, gasEnd.position, t);
}

but why is my “t” value always start at “0.2” not “0”? each time I start the game the value will be “0.2” how do I change my “t” value to “0” as default. I’ve tried using

function Start ()
{
	t = 0;
}

but it does not work. why is this happening?

bump

where is t defined? set it to zero by default. Since t is a temp variable it should be defined in the dropGas functon so setting it to zero at start wouldn’t work because dropGas wasn’t called yet so t wasn’t created.

I think I understand what you mean, I will try it later…thanks for the reply…I will update soon.