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.