Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by rtb · Dec 02, 2012 at 10:29 PM · movementarraysgameobjects

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
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges