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 /
  • Help Room /
avatar image
0
Question by edgema · Sep 03, 2016 at 07:24 AM · gameobjectinstantiaterandom.range

LevelGenerator after Checkpoint Respawn Not Aligning Tiles Properly

Pretty new at this, so apologies if I'm missing an easy bit of logic. Basically, I have a Crossy Roads style LevelGenerator that is called by the Manager at Start() and to build 30 tiles, then the LevelGenerator creates a tile everytime the player jumps forward. I have two different scales of tiles; some tiles are 2 units on the z, some are one unit. Works great until you respawn at a Checkpoint. When you respawn, I reset the levelgenerator's Vector3 to match the player, then recently the nearest fix I have done is pass in this line:

         levelGenerator.lastPos = Checkpoint.reachedPoint.z + 46.5f;

The 46.5 offset seems to work sometimes and sometimes not. I believe it is because, as I mentioned, some tiles are scaled 2 z, so randomly 30 levels could be at most 60 tiles and at least 30 tiles. Here's my code for the LevelGenerator:

 public class LevelGenerator : MonoBehaviour 
 {
     public List<GameObject> platform = new List<GameObject> ();
     public List<float> height = new List<float> ();
 
 
     private int rndRange = 0;
     public float lastPos = 0;
     private float lastScale = 0;
     public bool isVisible = false;
 
     public void RandomGenerator ()
     {
         rndRange = Random.Range ( 0, platform.Count );
         for ( int i = 0; i < platform.Count; i++ )
         {
             CreateLevelObject ( platform [i], height [i], i );
         }
     }
 
     public void CreateLevelObject ( GameObject obj, float height, int value )
     {
         //how we set the pieces in.
 
             if ( rndRange == value )
             {
             GameObject go = Instantiate ( obj ) as GameObject;
             float offset = lastPos + ( lastScale * 0.5f );
             offset += (go.transform.localScale.z ) * 0.5f;
             Vector3 pos = new Vector3 ( 0, height, offset );
             go.transform.position = pos;
             lastPos = go.transform.position.z;
             lastScale = go.transform.localScale.z;
             go.transform.parent = this.transform;
             }
     }
 }

Basically, I think the difference of the 1 and 2 on the lastScale is causing the issue. Is there any simple way that I could have the manager check for the number of tiles the LevelGenerator is returning on Start() or perhaps force it?

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
Best Answer

Answer by edgema · Oct 10, 2016 at 05:41 PM

Solved it. Turns out that it was an issue in the manager. The for loop was before the code to move the levelgenerator. If this happens to you and you have a level gen making tiles over the other, check that everything is in order first.

Comment
Add comment · 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

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

88 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

Related Questions

Random.range game object destroying itself before reaching destroy position.Please help. 1 Answer

instantiate prefab at every gameobject with tag 0 Answers

Problem with destroying a gameobject 2 Answers

local scale not working? 2 Answers

Reference GameObjects from an Array 1 Answer


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