|
I've created an obect, say a capsule, and in the scene windown i've rotated it 90 degrees, and now its a bullet. However when I instantiate this object, the rotation i've aplied the object/prefab doesn't follow through, and it still instantiates in its original orientation... Any ideas?
(comments are locked)
|
|
Which rotation are you using in the Instantiate instruction? If it's Quaternion.identity, the bullet keeps the same rotation as the prefab. If it is transform.rotation, then the object to which you've attached the script probably is rotated too - its rotation is combined to the original prefab's, producing the wrong direction. The code is part of the enemyscript.js, this controls enemy lives etc. i have this little bit of code: if(EnemyLives<=0) { Destroy(gameObject); var tempHundred: Transform; tempHundred = Instantiate(hundred,transform.position, transform.rotation); } But that don't work, i tried : which didn't do the rotation either, neither did it spawn at the enemies location (but i guess that cause the code didn't tell it too!)
Jul 22 '11 at 01:02 PM
BobbleHead
The above code fixed it! (i did some learning). however trying to get it to spawn at enemy location.. will post another question! Thank you!
Jul 22 '11 at 02:09 PM
BobbleHead
I've done it! haha var tempHundred: Transform; tempHundred = Instantiate(hundred, transform.position, Quaternion.Euler(90, 0, 0)); I am happy now
Jul 22 '11 at 02:12 PM
BobbleHead
It's the correct way: transform.position is the point at which you should instantiate the new object. You should also use transform.rotation instead of Quaternion.Euler(...) to keep the enemy orientation, but case this refuses to work you can keep the Quaternion.Euler thing. You will have problems only case the enemy dies in another orientation, because the new object will always be spawned facing the same side.
Jul 22 '11 at 04:38 PM
aldonaletto
(comments are locked)
|
|
maybe this is a little old, but I ran over the same issue and came up with two simple solutions: 1st- Place your object inside a empty game object at the desired rotation and create the prefab from this empty one. When you instantiate your prefab at identity rotation, the actual object inside the parent will keep the original saved rotation. 2nd- use this code to initialize object: Instantiate (myPrefab, new Vector3 (x ,y, z), myPrefab.transform.rotation); To be honest, I've not tried the second one, but I'm assuming it will spawn it at the prefab stored rotation. good luck!
(comments are locked)
|

Did you rotate the object before making it a prefab? If not, try doing so.
just tried this, and again, no luck =/
I'm instantiating with this code:
could that be the problem?
What is this attached to? I.E. Which
transformis getting passed to it? Because that's what's going to determine it's position and rotation.