• 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 /
  • Help Room /
avatar image
0
Question by Tariq-mehmood · Aug 03, 2017 at 07:57 AM · rotationinstantiatemodelsrigidbody.velocity

some Instantiated models are start rolling after getting Instantiated.

I am have problem in my endless game in which i am Instantiating traffic from a 2 points and every thing looks good except sometime some Instantiated models come towards me rolling as you can see in these pictures below. These models has been attached with MovingTraffic Script which just add velocity to the Instantiated model and those two points is attached with InstantiatingTraffic script through which these models are Instantiated and some models angles are not in there position therefore i have to assign those rotation angle through script please have a look on these script and models are attached with box collider, mesh collider, rigid body and movingTraffic Script

  //MovingTraffic Script
  public class MovingTraffic : MonoBehaviour {
 private BikeControl bikecontroll;

 // Use this for initialization
 void Start () {
     bikecontroll = GameObject.Find("Motorbike1").GetComponent<BikeControl>();
  
 }
 
 // Update is called once per frame
 void Update () {
     GetComponent<Rigidbody>().velocity = new Vector3(0, 0, -10);
 }

 }


//InstantiatingTraffic Script

 public class instanitaeingTraffic : MonoBehaviour {
 public GameObject car1;
 public GameObject car2;
 public GameObject car3;
 public GameObject car4;
 public GameObject car5;
 float time;
 public GameObject swampPoint1;
 public GameObject swampPoint2;

 public GameObject moterBike;
 public BikeControl bikeController;
 public float timeDecider;

 // Use this for initialization
 void Start () {
   //  GetComponent<Rigidbody>().freezeRotation = true;
 }

 // Update is called once per frame
 void Update()
 {
     var distance = Vector3.Distance(this.transform.position, moterBike.transform.position);

     //      Debug.Log(bikeController.speed);
     if ((bikeController.speed >= 1) && (bikeController.speed <= 50) && (distance >= 150))
     {
         GetComponent<Rigidbody>().velocity = new Vector3(0, 0, 10);
     }
     else if ((bikeController.speed > 50) && (bikeController.speed <= 100) && (distance >= 150))
     {
         GetComponent<Rigidbody>().velocity = new Vector3(0, 0, 50);
     }
     else if ((bikeController.speed >= 100) && (distance >= 150))
     {
         GetComponent<Rigidbody>().velocity = new Vector3(0, 0, 75);
     }
     else
     {

         GetComponent<Rigidbody>().velocity = Vector3.zero;

     }

     time += 0.01f;
     if (bikeController.speed >= 50)
     {
         timeDecider = 1;
     }
     else if (bikeController.speed >= 100)
     {
         timeDecider = 0.8f;
     }
     else if(bikeController.speed >= 150)
     {
         timeDecider = 0.5f;
     }else
     {
         timeDecider = 2;
     }
  //   Debug.Log(time);
     if ((time >= timeDecider))
     {
     int rendomCar = Random.Range(1, 6);
     int rendompoint = Random.Range(1, 3);
    
         if ((rendompoint == 1))
         {
             time = 0;
             if (rendomCar == 1)
             {
                 Instantiate(car1, swampPoint1.transform.position, transform.rotation);
             }
             else if (rendomCar == 2)
             {
                 Instantiate(car2, swampPoint1.transform.position, transform.rotation);
             }
             else if (rendomCar == 3)
             {
                 Instantiate(car3, swampPoint1.transform.position, Quaternion.Euler(0, 180, 0));
             }
             else if (rendomCar == 4)
             {
                 Instantiate(car4, swampPoint1.transform.position, Quaternion.Euler(-90, 90, -270));
             }
             else if (rendomCar == 5)
             {
                 Instantiate(car5, swampPoint1.transform.position, transform.rotation);
             }
             



         }
         else if ((rendompoint == 2))
         {
             time = 0;
             if (rendomCar == 1)
             {
                 Instantiate(car1, swampPoint2.transform.position, transform.rotation);
             }
             else if (rendomCar == 2)
             {
                 Instantiate(car2, swampPoint2.transform.position, transform.rotation);
             }
             else if (rendomCar == 3)
             {
                 Instantiate(car3, swampPoint2.transform.position, Quaternion.Euler(0, 180, 0));
             }
             else if (rendomCar == 4)
             {
                 Instantiate(car4, swampPoint2.transform.position, Quaternion.Euler(-90, 90, -270));
             }
             else if (rendomCar == 5)
             {
                 Instantiate(car5, swampPoint2.transform.position, transform.rotation);
             }




         }


     }

 }

}

this is what i am face please help me out on this problem and thanks in advance

alt text

asdasdasd.png (434.7 kB)
aasas.png (369.5 kB)
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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

142 People are following this question.

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

Related Questions

Instantiating a GameObject relative to another object's position and rotation 1 Answer

Trying to get objects to instantiate and move at different angles 1 Answer

Make rotation of two objects match in Unity3D 1 Answer

How can I Instantiate an object with a random y rotation but in 90 degree increments? 1 Answer

Im having an issue when Instantiate Prefab with specific rotation 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges