Search Unity

instantiateted object oriented wrong

Discussion in 'Prefabs' started by NiekvD, Apr 20, 2021.

  1. NiekvD

    NiekvD

    Joined:
    Apr 20, 2021
    Posts:
    1
    I am working on a game and i am making a system that can spawn buildings. I am now spawning the bottom of the building but it is oriented wrong. It has turned -90 degrees on the x axis and if i change the amount it rotates it is still wrong.
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class createBuilding : MonoBehaviour
    4. {
    5.     public int floors;
    6.     public GameObject RoofPrefab;
    7.     public GameObject floorPrefab;
    8.     public GameObject BottomPrefab;
    9.     public Vector3 BuildingPosition;
    10.  
    11.     void Start()
    12.     {
    13.        
    14.         Instantiate(BottomPrefab, BuildingPosition, new Quaternion(0, 0, 0, 0));
    15.     }
    16.  
    17.     void Update()
    18.     {
    19.        
    20.     }
    21. }
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Is the original BottomPrefab oriented correctly? If not, I'd fix it there.

    You didn't mention how you tried to change the amount it rotates.
     
  3. chubshobe

    chubshobe

    Joined:
    Jun 20, 2015
    Posts:
    52
    Use Quaternion.identity instead of creating a new quaternion with values of 0. Also generally, since quaternions are complex, use Quaternion.Euler() or quaterions already created by Unity.