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 LINKeRxUA · Jan 30, 2013 at 02:50 PM · rotationjavascripttransformdirectionpivot

How to rotate instantated prefab without rotating it's local directions by javascript?

I have created Wheel prefab. And instantiate it 4 times to get 4 wheels with one drawcall. Wheel have more datailed external side and less detailed internal side. During instantiation need rotate Front right and back right wheels - to make it's less detailed sides look inside. Rotation I try to do in 2 wrong ways:

 var fwStifness = 0.9;
 var swStifness = 0.25;
 var spring = 5500;
 var damper = 50;
 
 var Vehicle : GameObject;
 var Mesh_FL : GameObject;
 var Mesh_BL : GameObject;
 var Mesh_FR : GameObject;
 var Mesh_BR : GameObject;
 function Start () {
 Vehicle = Instantiate(Resources.Load("IS200-prefab", GameObject),Vector3.zero, Quaternion.identity);
     Mesh_FL = Instantiate(Resources.Load("Wheel", GameObject),Vector3.zero, Quaternion.identity);
     Mesh_BL = Instantiate(Resources.Load("Wheel", GameObject),Vector3.zero, Quaternion.identity);
     Mesh_FR = Instantiate(Resources.Load("Wheel", GameObject),Vector3.zero, Quaternion.identity);
     Mesh_BR = Instantiate(Resources.Load("Wheel", GameObject),Vector3.zero, Quaternion.identity);
 //*********************************************
 //....here was unnecessary code for my question
 //*********************************************
     Mesh_FL.transform.position = Vector3(-0.7,0.32,1.33);
     //1st way
     Mesh_FL.transform.localEulerAngles = Vector3(0,180,0);    
     //2nd way
     //Mesh_FL.transform.RotateAround(Mesh_FL.transform.position,Vector3.up,180);
     Mesh_FL.transform.parent = Vehicle.transform;
     Mesh_FL.name="FL";
     Mesh_FL.AddComponent(WheelCollider);
     Mesh_FL.GetComponent(WheelCollider).forwardFriction.stiffness=fwStifness;
     Mesh_FL.GetComponent(WheelCollider).sidewaysFriction.stiffness=swStifness;
     Mesh_FL.GetComponent(WheelCollider).suspensionSpring.spring=spring;
     Mesh_FL.GetComponent(WheelCollider).suspensionSpring.damper=damper;
     
     //Mesh.FL.GetComponent(WheelCollider).suspensionSpring.damper=5500;
     
     
     Mesh_FR.transform.position = Vector3(0.7,0.32,1.33);
     Mesh_FR.transform.localEulerAngles = Vector3(0,0,0);
     Mesh_FR.transform.parent = Vehicle.transform;
     Mesh_FR.name="FR";
     Mesh_FR.AddComponent(WheelCollider);
     Mesh_FR.GetComponent(WheelCollider).forwardFriction.stiffness=fwStifness;
     Mesh_FR.GetComponent(WheelCollider).sidewaysFriction.stiffness=swStifness;
     Mesh_FR.GetComponent(WheelCollider).suspensionSpring.spring=spring;
     Mesh_FR.GetComponent(WheelCollider).suspensionSpring.damper=damper;
 }
 function Update () {
 Mesh_FL.transform.Rotate(10 * -6 * Time.deltaTime, 0, 0);
 Mesh_FR.transform.Rotate(10 * -6 * Time.deltaTime, 0, 0);
 }

On update this wheels are rotating in different ways (because their pivot directions look in different ways)

How can I rotate mesh of wheel prefab after instantiation without changing pivot direction? Thank you, and sorry for my poor English.alt text

alt text

unity3d-questionpivot.jpg (99.2 kB)
unity3d-questionpivot2.jpg (52.7 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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Julien-Lynge · Jan 30, 2013 at 06:14 PM

As I understand it, you want to rotate an object without changing its axes. That simply isn't possible - it's the same as saying "I want to rotate this without rotating it"

There are ways to achieve the same effect, however. The easiest way is to add a parent to the object. You can then rotate the object without rotating the parent. The parent axes won't move, and the child axes will.

Alternatively, you can modify the mesh itself. I wouldn't suggest that for a beginner.

Comment
Add comment · Show 3 · 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
avatar image LINKeRxUA · Jan 31, 2013 at 10:00 AM 0
Share

That's bad idea to edit mesh - because that mean to make an internal side of a wheel more detailed. I think that it's not good to grow up trianglecount in unaccessible places for $$anonymous$$ainCamera shot in scene.

Instantiate another prefab with rotated axis in right directions - is to waste 1 more drawcoll.

So I will try to operate with Empty GO and child\parent. P.S. I'will not close this question and mark your answer as best for few days. Hope never dies. Just believe. If no one will offer me another solution - then the question will be closed.

avatar image LINKeRxUA · Jan 31, 2013 at 10:07 AM 0
Share

http://answers.unity3d.com/questions/390323/how-to-make-my-new-instances-spawn-in-the-right-di.html

Here is something.. want to try..

avatar image HappyLDE · Mar 21, 2015 at 10:47 PM 0
Share

I have the same problem, all 4 wheels are facing the same side :( any tutorial that $$anonymous$$ch this aspect?

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

10 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

Related Questions

[JS] transform.rotation not working 1 Answer

I need an object to rotate using a moving object as a pivot. 0 Answers

Change object position on trigger enter 3 Answers

Rotating Rigidbody properly using AddRelativeForce 0 Answers

How would I rotate an object relative to another without parenting? 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