Topic locked

GameObjects spawning in wrong place

November 8, 2014 - 11:36am #7

I have a number of spheres as children of the main object attached to an imagetarget that is a scene with four other image targets.

The image target in question is positioned at 107.5788, 0, 0

The main game object attached to this image target is positioned at 0,0,0

The sphere attched to the game object is positioned at 0.0638326, 0.01016547, 0.6540853

I save the starting transform.position of the sphere on awake

The sphere is translated off in some random direction and when a given time passes I reset its transform.position back to the saved transform.position

But the sphere appears way off to the thinks not relative to its parent so in totally the wrong place.

Been trying all manner of things all day and cannot get the sphere to return to its original start position....????

GameObjects spawning in wrong place

November 9, 2014 - 11:35pm #6


I have even tried changing the world center to all available options and it still appears in wrong direction.


	GameObject obj = (GameObject)Instantiate (MyObjectPrefab.transform,, MyObjectPrefab.transform.rotation);
						obj.transform.parent = hit.collider.gameObject.transform;
						obj.transform.position = new Vector3(0.0638326, 0.01016547, 0.6540853);


GameObjects spawning in wrong place

November 10, 2014 - 5:41am #5

If you want to keep the sphere position consistent relative to its parent game object, you should probably use transform.localPosition (as opposed to transform.position, which instead sets the position in absolute World coordinates).

See also:


GameObjects spawning in wrong place

November 10, 2014 - 7:11am #4

Hi,  OK so I changed to localPosition but still weirdness abounds?

What I have done is to move the imagetarget to 0,0,0 and aligned the camera at 0 on the x axis

Oddly the sphere still appears in the wrong place, but now lower rather than left.  I started to dig deeper and fid that my objects are rotated and so now for my sphere the coords are like xz,y.

After trial and error manually ajusting the values in my script I got it to appear right, but still at a a loss at to why the value reported in the editor when the sphere starts does not reset right?


Thanks for you help


GameObjects spawning in wrong place

November 10, 2014 - 7:14am #3

The easiest way to understand how the axis are oriented for an Image target and its children objects is to create an Image Targets in the Unity scene, attach a few objects underneath it (as children) and then check the axis orientation of each game objects starting from the base Image Target object and then navigating down the hierarchy of your objects.

This should hopefully make it more obvious.




GameObjects spawning in wrong place

November 10, 2014 - 2:39pm #2

AlessandroB thanks!

I now see where I was going all wrong re the coordinate system as not only was I not using localPosition once I started to use it I was in fact using the sphere prefab global position instead of local!

I followed your advice re the testing the relationship of world/local on objects and all is clear ;-)


Great help cheers

GameObjects spawning in wrong place

November 11, 2014 - 1:05am #1

Glad to help ;-)

Topic locked