Player starts out with some amount of fuel and life support. If they get their ship to a planet, their ship ‘refuels’ and they are back to full fuel and life support, otherwise these values are drained as they are used (life support should be a constant drain unless they are in within 100 of a planet.)
right now life support is never draining, and i have NO IDEA why. here is my code.
var force = 3.0;
private var targetPosition:Vector3;
private var velocity = Vector3.zero;
public static var fuel = 300.0f;
public static var lifeSupport = 1000.0f;
private var lifeSupportResetDistance = 100.0f;
private var one = (GameObject.Find ("Planet_1"));
private var two = (GameObject.Find ("Planet_2"));
private var three = (GameObject.Find ("Planet_3"));
private var four = (GameObject.Find ("Planet_4"));
private var planets = new Array();
private static var refueling : boolean;
function Start () {
planets[0] = one;
planets[1] = two;
planets[2] = three;
planets[3] = four;
refueling = false;
}
function Update () {
refueling = false;
if(lifeSupport == 0.0f)
{
Application.LoadLevel("DeathScreen");
//ur dead
}
if(Input.GetMouseButton(0))
{
if(lifeSupport > 0.0f){
if(fuel > 0.0f){
var pos = Input.mousePosition;
pos.z = Camera.main.transform.position.y;
pos = Camera.main.ScreenToWorldPoint(pos);
var targetRotation = Quaternion.LookRotation(pos - transform.position);
velocity += transform.forward * Time.deltaTime * force;
fuel--;
}
}
}
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
//alter 70.5 to change speed
transform.position += velocity * Time.deltaTime * 70.5;
for (var i = 0; i < planets.length; ++i)
{
if((Mathf.Abs(Vector3.Distance (transform.position, planets*.transform.position))) <= lifeSupportResetDistance)*
-
{* -
refueling = true;* -
}* -
}* -
if(refueling == true){*
-
fuel = 150.0f;* -
lifeSupport = 500.0f;* -
} else {*
-
refueling = false;* -
lifeSupport--;* -
}*
}
this is in javascript. If some one could help me tweak this code to get the desired result (life support drains unless player is near a planet object) or at least point out what ive done wrong then that would be fantastic!
if im not within distance, then life support should be draining. it is not draining.
– TSI25