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 khfrekek · Aug 04, 2016 at 05:36 AM · instantiateprefabspawnscrollinggaps

Spawned Scrolling background objects gaining a gap when speed increases.

Hi everyone!! I am making a game with an infinite background scroller that has an increasing speed. This background is made up of prefab blocks (with scroller spricpts attached) that are consistently instantiated to the right of the camera, such that their edges touch perfectly with no overlap or gap.

These blocks (all the same width) are spawned using a script that spawns a new block whenever the previous block has moved by the width of the block, using the following script:

 void Start()
     {
         lastPosition = meter.transform.position;
     }
 
     void Update()
     {
         meterDistance += Vector3.Distance(meter.transform.position, lastPosition);
         lastPosition = meter.transform.position;
         if (meterDistance >= 2.9f) //width of the prefab blocks
         {
             meterDistance = 0f;  //reset the "distance meter"
             Spawn(); //spawn a new background object
         }
     }

and these prefab blocks are using a scroller script as follows:

 void FixedUpdate()
     {
         //Scrolls the background (and obstacles) backwards by the scrollspeed. destroys when it gets too far
         newPosition = transform.position;
         newPosition.x -= PlayerController.scrollspeed;
         transform.position = newPosition;
         if (transform.position.x <= -20f) Destroy(this.gameObject);
     }

And this actually works perfectly; at least when the game begins at a constant scrollspeed.

However, when the scrollspeed increases, the objects start spawning in a lagged fashion: creating gaps in between every block of width proportional to the scrollspeed.

This makes no sense to me, because the spawn time is determined by the DISTANCE traveled, which is definitely proportional to the scrollspeed of that object. So does anyone have any idea why gaps would be appearing?

Thank you so much for your time and help! Zack

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

instatiates at a bad position 1 Answer

Error: Instantiated Enemies don't get hit 2 Answers

Spawning unique prefabs at different transform posititions 0 Answers

Give prefab a parent 2 Answers

How to spawn a 'boss' after all enemies defeated and then kill that 'boss'? 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