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 POLYGAMe · May 01, 2014 at 05:27 AM · transform.positiontransform.rotation

Car rotations not being set properly

When my player car hits a traffic trigger box, my script searches for an inactive car and sets it at the position of a spawner. Each traffic box has several spawners. Both the spawners and cars are stored in arrays.

For some reason, my code isn't working. The cars don't align properly with the spawners, both rotation and position. Some spawners are worse than others. It's really strange... most of the time, the cars are put exactly where the spawners are but on a couple of them, the car is placed off to the side and it goes through the wall. Also, the rotation is never right.

What's wrong with my code? I thought it looked pretty decent and should work but I'm having no luck...

 function OnTriggerEnter(Other : Collider)
 {
     if (Other.tag == "Player")
     {
         if (Traffic_Script.g_iCarsActive < Traffic_Script.g_iMaxActiveCars)
         {
             iRandom = Random.Range(0, SpawnerArray.Length + 1);
         
             for (var i = 0; i < iRandom; ++i)
             {
                 iIndex = Random.Range(0, AICarArray.Length); 
                 
                 if (!AICarArray[iIndex].active)
                 {
                     AICarArray[iIndex].transform.position.x = SpawnerArray[i].transform.position.x; // Set car pos to spawner pos
                     AICarArray[iIndex].transform.position.y = SpawnerArray[i].transform.position.y + 1; 
                     AICarArray[iIndex].transform.position.z = SpawnerArray[i].transform.position.z; 
                     AICarArray[iIndex].transform.rotation = SpawnerArray[i].transform.rotation; 
                     AICarArray[iIndex].SetActive(true);
                 }
                 else
                 {
                     print("Car already active");
                 }
             }
         }
     }
 } 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by POLYGAMe · May 01, 2014 at 06:29 AM

Turns out it was an issue with another script. I had it adjusting the car's Y axis rotation, depending on if the car was travelling north or south. When I put all the code into the script above, it worked. I have no idea whey it didn't before, perhaps an order of operations thing...

Anyway, seems to work fine now!

Comment
Add comment · Share
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

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

20 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

Related Questions

How to align & rotate objects to each other at run time? 1 Answer

How to Move and Rotate Ball at the same time by code 0 Answers

any way to access the global position and rotation of a child object? 1 Answer

Vertical Camera Orbit 0 Answers

How to get updated Transform of a spawned object? 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