- Home /
 
objects in the same array wont move
i have a problem trying to move 2 objects (clouds) across the sky independently of each other. The two clouds (that start in diffrent locations) and are supposed to move, but they dont.
i want them to move in difrent directions... i just cant figure out why the scripts i have cause this problem. i hope someone can help me solve this annoying issue... thanks in advance :)
script 1 "Move_Clouds": (attached to an empty gameobject call GameTime)
 #pragma strict
 
 var cloud : GameObject[]; //the array that holds the two game objects
 var GT : GameObject;
 var i : int;
 private var step : float = 0.0f;
 var ismovingback : boolean = false;
 
 var reverse_X : Vector3;
 private var reverse_Z : Vector3;
 var duration : float = 2.0f;
 
 function Start() 
 {
  var randomDirection : Vector3 = new Vector3(Random.Range(-359, 359),Random.Range(-359, 359),Random.Range(-359, 359));
  transform.Rotate(randomDirection);
 }
 
 function Update()
 {
   Go = GameObject.Find("GameObject");
   var Cloud : Cloud_control = Go.GetComponent.<Cloud_control>();
   
   for(i=0;i<cloud.length;i++)
   {
      var ob = cloud[i];
   }
   
   if(Cloud.obj == true && ismovingback == false)
   {
     MoveBack();
   }
   else if(Cloud.obj == false && ismovingback == true)
   {
   }
   else if(Cloud.obj == false && ismovingback == false)
   {
     cloud[Random.Range(0, cloud.Length)].transform.position += new Vector3(2,0,2)* Time.deltaTime; //should move the clouds randomly on the x and z (i think this is somehow resposible for the problem)
   }
 }
 
 function MoveBack() //should move the cloud that left the collider back in
 {
     var ob = cloud[i]; //should get specific cloud in the array that needs to be moved back
     reverse_X = transform.position += new Vector3(-3,0,0); //should move the cloud back on the x
     reverse_Z = transform.position += new Vector3(0,0,-3); //should move the cloud back on the z
     
     step = Mathf.Clamp01(step);
     var delta : float = (Time.deltaTime / duration);
     step -= delta;
     ob.transform.position = (Vector3.Lerp(reverse_X, reverse_Z, step));
     ismovingback = true;
 }
 
               script 2 "Cloud_control": (attached to empty gameobject (called GameObject) with a sphere collider that covers the map)
 #pragma strict
 
 var obj : boolean = false;
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 function OnTriggerExit(cout : Collider) //detects if a cloud has gone too far forward
 {
      
     if(cout.tag == "Cloud")
     {
     obj = true; //stops the cloud that left the collider from going too far forward.
     }
 }
 
               script 3 "Clouds_forwad": (attached to a empty gameobject with a box collider, is placed behind both clouds for obvious reasons)
 #pragma strict
 
 var GT : GameObject;
 var obj : boolean = false;
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 function OnTriggerEnter(cout : Collider)
 {
      GT = GameObject.Find("GameTime");
      var forward : Move_Clouds = GT.GetComponent.<Move_Clouds>();
      
     if(cout.tag == "Cloud")
     {
     forward.ismovingback = false; //stops the cloud that hit it from going too far backward
     }
 }
 
              Your answer
 
             Follow this Question
Related Questions
Moving Gameobject and Reseting Issues 3 Answers
Make object go back to original spawn distance (Similar to Rust building system) 1 Answer
3D Grid Based Movement (X-Com 2012 etc) – How to implement vertical movement? 0 Answers
How can I join 2 objects when objectB enter in objectA' s collider? 1 Answer
Get a GameObject from a component 1 Answer