Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

instantiate into any place in the hierarchy

Discussion in 'iOS and tvOS' started by Overunity3d, Sep 5, 2010.

  1. Overunity3d


    Sep 5, 2010
    I fire a bullet. My firing vectors are not in the world object. But the object passes through the world on its own coords and vectors. It keeps going straight even though I spin the world. In other words when I spin I can spin to locate a target after I fire. This would a be good laser. But I want a bullet after I fire but the trajectory follows my line of sight. The bullet keeps going forward from my point of view.
    The instantiation prefab is at the root of the game hierarchy not at the same level as the spawnpoint.
    Do I need to copy the world vectors to the prefab vectors in the update function of the prefab? I think I just answered my own question. Anybody else?
    Or can I instantiate a prefab into any place of the hierarchy so that it follows the parent?

    Again the prefab never follows the world vectors because the instantiation is at the different level of the hierarchy and was instantiated with its own private vectors and quaternions. Correct?
  2. StarManta


    Oct 23, 2006
    You can change its place in the hierarchy after you instantiate.
    Code (csharp):
    2. var g = Instantiate(blah blah);
    3. g.transform.parent = transform;
  3. andeeeee


    Jul 19, 2005
    It's quite easy to convert a direction in local coordinates to world coordinates (eg, so you can fire along a gun's forward axis, but the bullet travels in world space):-
    Code (csharp):
    1. var worldDir = transform.TransformDirection(localDir);