Search Unity

instantiate into any place in the hierarchy

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

  1. Overunity3d

    Overunity3d

    Joined:
    Sep 5, 2010
    Posts:
    14
    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

    StarManta

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

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    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);