Object Spawning Problems :(

Hello,

I have a small scene in which you have a top down camera and the ground is full of tiles. When you click on one of the tiles, you choose what is to be put there. I,e you select a tile and choose “Place Chair”; A chair will appear.

The problem is, when the chair spawns at the specified tile, it is not rotated correctly.
Here is the code:

 var bobbygui : boolean = false;

var Chair2 : GameObject;





function OnMouseDown()

{

  bobbygui = true;

}



function OnGUI()

{

  if (bobbygui == true)

  {

    GUI.Box(Rect(0,0,300,500),"Inventory");

    if (GUI.Button(Rect(0,0,100,50),"Chair"))

    {

      print ("Selected Chair");

      Instantiate(Chair2,new Vector3(72,3,57),Quaternion.identity);

    }

  }

}





///Le Done*

Any help would be much appreciated. Thanks :slight_smile:

I think you have the same problem as i had before, not sure how to fix it, but you can add another script which rotates your object instantly after spawning…

I used this script to correct the placement of wrong objects:

var rotX = 0.0;
var rotY = 0.0;
var rotZ = 0.0;

var posX = 0.0;
var posY = 0.0;
var posZ = 0.0;

var rot = false;
var pos = false;
var setpos = false;

function Start () {

if (pos == true)
if (setpos == true)
transform.position = (Vector3(posX,posY,posZ));
else
transform.position += (Vector3(posX,posY,posZ));


if (rot == true)
transform.Rotate(Vector3(rotX,rotY,rotZ), Space.World);
}

Probaly not the most effective way, but i hope it helps :wink:

When you import the model, is it rotated correctly from your modelling application? If not, you may need to adjust the rotation in your modelling app to be imported correctly. Then upon instantiation it is rotated correctly in Unity.