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 Giantbean · Jan 22, 2014 at 11:02 PM · instantiateassetbundletranslatetransform.translate

instantiating transform.translate in the wrong position?

This is likely a silly mistake I'm making but it has me stumped.. I have an object in this example which takes customization for ease of explaining we will say its a car. The "car" is loaded into the scene with an asset bundle the loader script is attached to a null object targeted by a camera. This "car" loads in and is placed in the scene with a rotation and translation. All this works fine.

The trouble is this "car" has objects that it loads from assetBundles, accessories, And they load in the wrong place. For now lets just say the tires are loaded separate from the car allowing the tire to be say a sports tire or a monster wheel. So once the car is in place it has a script which loads more assets. It loads a single tire and instantiates the tire 4 times. but the tires are not going where I tell them to. The Y position and the rotation are right but the X and Z are wrong.

So here is what my code looks like.

     yield return download;
                 
                 assetBundle = download.assetBundle;        
                 
                 loadedAsset1 = Instantiate(assetBundle.mainAsset) as GameObject;
                 loadedAsset1.name = Asset_One;
                 loadedAsset1.transform.Rotate(R1, R2, R3);
                 loadedAsset1.transform.Translate (targetOnePosition.x,targetOnePosition.y,targetOnePosition.z);
 
 loadedAsset2 = Instantiate(assetBundle.mainAsset) as GameObject;
                 loadedAsset2.name = Asset_two;
                 loadedAsset2.transform.Rotate(R1, R2, R3);
                 loadedAsset2.transform.Translate (targetTwoPosition.x,targetTwoPosition.y,targetTwoPosition.z);

Rinse and repeat for the other two "tires"

As you may be able to guess from the code I have public variables allowing me to set the name, translation and scale for each instantiated object. I could use a vector3 for targetRotation the same way I do for targetOnePosition, or use floats of P1,P2 and P3 for the positioning as I have for the rotation in the above example. Either way the results are the same. The rotation currently works fine (I'm only rotating the "y" axis anyways) but the transform only gets the right float for the Y. if I set it to (0,1,0)its OK but (1,1,0) turns into (-0.7071069, 1, 0.7071067)

Once I can get the "tires" on I will need to be able to add a second, third, fourth or more assets for accessories like spoilers or... I don't know hood spikes. I will deal with that later but for now does anyone know why the instantiated copies of an assetBundle would reposition themselves?

the positioning code on the base "car" frame looks like this:

 yield return download;
         
             assetBundle = download.assetBundle;        
             
             loadedAsset = Instantiate(assetBundle.mainAsset) as GameObject;
             loadedAsset.transform.Rotate(0, 45, 0);
             loadedAsset.transform.Translate(0, 1, 0);

It comes in right where I want it, however if I change the transform.translate from (0,1,0) to something like (2,1,0) the object is instantiated at (1.41423, 1, -1.414214) instead? So why is the translate.Transform not moving objects where I'm telling it to?

The assetBundles Base position and rotation is zeroed out when the bundle is made so i don't think I have any competing transforms or rotations as seen in similar posts.

Any suggestions would be appreciated Thanks.

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

Answer by Giantbean · Jan 23, 2014 at 10:18 PM

I swapped:

 loadedAsset.transform.Translate (targetOnePosition.x, targetOnePosition.y, targetOnePosition.z);

for:

 loadedAsset1.transform.position = new Vector3(targetOnePosition.x, targetOnePosition.y, targetOnePosition.z);

And it is working now. Seems to be something with the local vs object position and rotation.

I read the documentation on both before making my first post but it is still confusing to me. It seems translate takes local rotation of the object into account and position does not. Using transform i would have to convert the local to world space but with position it is moving in world space without any extra code.

I'm not sure which way is better but my code is working now so I'm OK with it.

If anyone wants to correct me on any this feel free.

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

19 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

Related Questions

Auto Translate after cloning gameobject using Instantiate() 1 Answer

Create an AssetBundle with prefabs containing imported models 0 Answers

Custom movement problem 1 Answer

How to keep cameras Vector3.y Position While Translating it. 1 Answer

Position an instantiated prefab relative to its translation vector 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