Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • 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.

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

Character Shooting Mechanic 2D Issues 0 Answers

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


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