Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 NinjaRubberBand · Feb 20, 2014 at 05:07 PM · positionrandom

Spawn position is different

Im making a game for android where when you tap on the screen, the gravity changes and you can walk on the ceiling. Just like gravity guy! But what is different in this game is that its random generated. So i made some obstacles of cubes and put them in an empty game object. I then put it in a prefab and dragged it into my spawn-script. I have 4 different obstacles. The spawn script is attached to a cube which spawns the obstacles about every 7 sec. And this is where the problem appears.

When these obstacles spawns its a different position on thex axis they spawn. Little hard to explain, but i have some pictures that can explain some.

First picture: https://www.dropbox.com/s/lp5trrh7zibtdpk/spawnposition.tiff

Second picture: https://www.dropbox.com/s/rfublvsmnx84pct/spawnposition2.tiff

These are two obstacles i have in my game. The cube that is on both pictures somewhere between the two obstacle pictures, is the spawner. I took the picture right after they spawned. As you can see in the last picture, the obstacle spawned, where the spawner was in the middle. But in the first picture, the spawner is on the left side. And that irritates me a lot. it also happens with some of the other obstacles. How can i fix this? If you have any questions, plz ask.

Spawner script:

 #pragma strict
 
 //Instantiate(asteroid, myposition.transform.position, myposition.transform.rotation);
 
 var rndNum:int;
 
 
 var course1 : Transform;
 var course2 : Transform;
 var course3 : Transform;
 var course4 : Transform;
 var course5 : Transform;
 var course6 : Transform;
 
 var myposition : GameObject;
 var spawn = true;
 
 function Start() {
 
 
  while(true) {
 var rndNum:int = Random.Range(1 , 5);
 Debug.Log(rndNum);
 if(rndNum == 1)
 {
 transform.position.y = -2.100585;
 Instantiate(course1, myposition.transform.position, myposition.transform.rotation);
 
 }
 
 if(rndNum == 2)
 {
 transform.position.y = 1.195426;
 Instantiate(course2, myposition.transform.position, myposition.transform.rotation);
 
 
 }
 
 if(rndNum == 3)
 {
 transform.position.y = 1;
 Instantiate(course3, myposition.transform.position, myposition.transform.rotation);
 
 }
 
 if(rndNum == 4)
 {
 transform.position.y = 0.2;
 Instantiate(course4, myposition.transform.position, myposition.transform.rotation);
 
 }
 
 
 if(rndNum == 5)
 {
 
 Instantiate(course5, myposition.transform.position, myposition.transform.rotation);
 
 }
 
 if(rndNum == 6)
 {
 
 Instantiate(course6, myposition.transform.position, myposition.transform.rotation);
 
 }
 
 yield WaitForSeconds(22);
 }
 }
 
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

0 Replies

· Add your reply
  • Sort: 

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

18 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

Related Questions

spawn muzzle flash with random rotation? 2 Answers

Random position without overlap. HELP! 1 Answer

How can I calculate and place a GameObject at a random place just outside the camera frustrum? 0 Answers

How do I randomly place doors, treasure chests, and traps in a randomly generated maze? 0 Answers

Random position inside multiple areas 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