Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by LeePorter · Jul 10, 2019 at 12:56 PM · instantiatebeginner

why do my instantiated prefabs spawn depending on the position / rotation of the globe?

i have a globe which spins by its self and when the player clicks and drags the globe they can drag it into what ever position the wish. i have it where when a specific button is pressed, buildings are instantiated onto the globe but they dont always spawn in the right orientation on the globe i.e. on their side, upside down etc. i have a feeling its to do with the position of the camera but im not too sure! how do i fix this? i am a bit of a beginner so i am unsure where i have gone wrong.

here is my rotate script where the player can click and drag the globe

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class rotateEarth : MonoBehaviour
 {
     Vector3 mPrevPos = Vector3.zero;
     Vector3 mPosDelta = Vector3.zero;
     public EarthSpinScript earthSpin;
 
     // Update is called once per frame
     void Update()
     {
         if (Input.GetMouseButton(0))
         {
 
             mPosDelta = Input.mousePosition - mPrevPos;
             if (Vector3.Dot(transform.up, Vector3.up) >= 0)
             {
 
                 transform.Rotate(transform.up, -Vector3.Dot(mPosDelta, Camera.main.transform.right), Space.World);
             }
 
             else
             {
 
                 transform.Rotate(transform.up, Vector3.Dot(mPosDelta, Camera.main.transform.right), Space.World);
             }
 
             transform.Rotate(Camera.main.transform.right, Vector3.Dot(mPosDelta, Camera.main.transform.up), Space.World);
 
         }
 
 
 
         mPrevPos = Input.mousePosition;
 
 
         earthSpin.spinEarth = false;
         earthSpin.spinEarth = true;
        
      
     }
 }

here is my instantiate script

 public class Spawner : MonoBehaviour
 {
     public Transform[] spawnLocations;
     public GameObject[] WhatToSpawnPrefab;
     public GameObject[] WhatToSpawnClone;
     public bool alreadyInstantiated;
 
 
 
     public void Update()
 
     {
 
 
 
         SpawnBuilding();
 
 
 
         void SpawnBuilding()
 
 
         {
             if (Input.GetKeyDown("1") && !alreadyInstantiated)
 
             {
                 alreadyInstantiated = true;
 
                 GameObject go = Instantiate(WhatToSpawnPrefab[0], spawnLocations[0].transform.position, Quaternion.Euler(85, 90, 360)) as GameObject;
                 go.transform.parent = GameObject.Find("Globe").transform;
             }
 
             else
             {
                 alreadyInstantiated = false;
             }
         }
 
     }
 
 }

and here is my earth spinning script

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class EarthSpinScript : MonoBehaviour
 {
     public float speed = 10f;
     public bool spinEarth = false;
    
 
    
     //globe spins
 
 
     void Update()
 
     {
         if (spinEarth) 
 
 
         {
             transform.Rotate(Vector3.up, speed * Time.deltaTime, Space.World);
 
         }
 
         
 
     }
 
     public void StopSpinning()
     {
         spinEarth = false;
 
     }
 
     public void StartSpinning()
     {
         spinEarth = true;
     }
 }

hopefully you can spot something in my scripts because I'm puzzled!

thank you in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Magso · Jul 10, 2019 at 09:58 PM

Where did you get Quaternion.Euler(85, 90, 360) from? This needs to be set to a rotation based on the camera or the spawnLocation. If the spawnLocation is at the correct rotation use

 spawnLocations[0].transform.rotation

or if you want to use the cameras rotation, allow for the angle offset the camera might have e.g

 Quaternion.Euler(cameraObject.transform.eulerAngles + new Vector3(-15, 0, 0))
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image LeePorter · Jul 12, 2019 at 01:07 PM 0
Share

neither of these seem to be working for me :/

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

143 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make objects spawn at the same time without colliding ? 1 Answer

[SOLVED]: Bullets passing through platforms - Brackeys Tutorial 1 Answer

Instantiate not working? 0 Answers

How to instantiate a sprite after it has been destroyed? 2 Answers

how do I make it so my building prefab instantiates only once 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges