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 11, 2017 at 06:53 AM · instantiaterigidbody.addforcerigidbody.velocity

Instantiated object start rotation

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

alt text

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

122 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

Related Questions

ForceMode.VelocityChange not behaving as expected 1 Answer

Speed limit to AddForce (without limiting velocity of rigidbody) 0 Answers

2D Rigidbody Velocity Being Weird 1 Answer

my 2d character isnt jumping with constant velocity on applying force 1 Answer

some Instantiated models are start rolling after getting Instantiated. 0 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