- Home /
GameObject change Position after game started
i have problem with my gameobject, everytime after i start the game, the Object's Y axis position changes on its own , can somebody explain to me why is this happening and how to handle this ?
this is the instantiation code, here i set the Y to 1.0f
Vector3 spawn = new Vector3(spawnPointX, 1.0f, spawnPointZ);
if (type == 1)//minion
{
newArmy = (GameObject)Instantiate (Minion, spawn, Quaternion.identity);
script = newArmy.GetComponent<MinionBehaviour>();
}
this is the initiation code in the gameobject's monobehaviour, again, i set the Y to 1.0f too here
public virtual void InitiateArmy(int side, float x, float z){
transform.position = new Vector3(x, 1.0f, z);
//some other lengthy initialization
}
this is the prefab, again, the pre-set value for Y is 1.0f, no rigidbody no gravity
and yet, when i press play, the Y position of the object is turned to 0.583333 i don't even know where the heck that number came from
can anyone explain why this is happening ? and how to handle it ? thanks
Answer by slavo · May 10, 2017 at 04:16 PM
Hello, it is Navmesh agent swapping to navmesh. To solve this, put your graphics (cube at the moment) in child GameObject and offset it so root transform would be at bottom of cube
hi, can you explain what "navmesh agent swapping to navmesh" means ? i tried to put the model in the child gameobject before and I ended up having problem with the collider (it didn't collide), thanks
Your answer
Follow this Question
Related Questions
Spawn Prefabs 1 Answer
How to instantiate a prefab with a script attached? 2 Answers
I cant delete multiple instantiated prefabs 0 Answers
How do I get the global position 2 Answers