- Home /
Clones of an object have a wrong position
Hi, i'm creating a 2D endless runner game and i must spawn obstacles at runtime. In the scene there's only an obstacle object that has the right Y value,but when i run the game all the other clones of the obstacle have a wrong Y position and so they aren't visible in the scene because they are covered by another object (the platforms).
public class spawnTerra : MonoBehaviour {
public GameObject lamaRot; //lamaRot is the obstacle object
public Vector3 nextPosLama;
public Transform hero; //hero is the player
void Update()
{
nextPosLama.x += hero.position.x + Random.Range(1, 6);
nextPosLama.y = 5 / 10;
Instantiate(lamaRot, nextPosLama, Quaternion.identity);
}
}
How can i fix this boring problem??? Thanks in advance guys :D
Simply modify their position the line after they are instantiated.
Answer by robertbu · Aug 03, 2014 at 02:44 PM
@Danisuper - Are you sure the pivot point is at the correct position for your obstacles? If the obstacles came from an modeling program, temporarily replace them with a built-in object like a cube or a sphere. If the cube and sphere work, then you will need to fix your obstacles in either the modeling program or by using an empty game object as a parent. If the cube/sphere are in the wrong position, then you have a logic error in your positioning code.
Yes, you were right :P,changed the pivot and everything worked. sorry for my noobness ^^'. Thanks everybody