- Home /
Help with local/world positiong a new gameobject
Trying to understand child and its position inthe world but under a parent.
So I have a Player , who has a spawn point infront of him as a child.
I use this spawn point to spawn bullets coming from his forward direction, but when i do that it ends up in the wrong area and i'm guesing it's to do with local and world?
GameObject star = (GameObject)Instantiate(Resources.Load("Bullet"));
star.transform.position = player.transform.FindChild("starSpawnPoint").transform.position;
EDIT--- So when I try to get an object to take the position of another object. It dosen't spawn correctly to that position.
star = (GameObject)Instantiate(Resources.Load("NinjaStar"),GameObject.Find("starSpawnPoint").transform.position,Quaternion.identity);
This code does work and the sphere does end up at 0,0,0.
GameObject go = (GameObject)GameObject.CreatePrimitive(PrimitiveType.Sphere);
go.transform.position = Vector3.zero;
Your code looks fine. It's hard to say what the problem is without having more detail. What is the pattern to where the bullets end up? Is it always at the same location in the world, or always at the same position relative to the player?
The player never moves the camera is locked on from a angled down view of the player. And THe bullets do end up at the same place each time.
Answer by Borgo · Feb 04, 2011 at 11:32 AM
Try to see in your moddeling software if your model are in the middle of the scene.
In Unity just put your bullet model in the scene, let it alone, without parent and set the positions to 0,0,0, if it isn't in the center of the world scene, so, your model are out of align.
So I went ahead and put a script to add a primitiveshape at the 0.0.0 location. Which it does show up at 0,0,0 and it shows up under my player cause my player is also position on 0,0,0.
Your answer

Follow this Question
Related Questions
Attaching Object as child at certain point in animation 2 Answers
Prefab, procedural attachment of child, childCount return 0 1 Answer
Instantiate and Scaling 0 Answers
Create Clones as children in loops? 1 Answer
Instantiate as a Child of the Parent 4 Answers