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 Destava · Jul 01, 2015 at 10:37 AM · javascriptobject

A lot of objects in 1 scene

I'm making a top down space game, and I've made a script that will generate stars in a specific area. Now if I pick a really big area, say from x-1000 to x1000 and y-1000 to y1000, and generate a lot of stars in there. The game starts lagging, because I have all the stars bound to an empty object, and the empty object has a script attached to it. Which will make the stars stay in the background and move slower according to the movement of the ship. Now my question is, is there any way to make it so that the game doesn't lag when there are a lot of moving objects involved?

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

Answer by LaneFox · Jul 01, 2015 at 11:12 AM

Creating individual gameobjects for something as prolific as stars is not a good idea.

Why don't you just make a few textures and layer them at different depths so they move at various rates relative to the ship? This is much more standard, reduces load and is easier to do.

Comment
Add comment · Show 3 · 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 Destava · Jul 01, 2015 at 03:47 PM 0
Share

How do I layer them so that they move at various rates? Because I did some testing, and I found out that when I take the script that makes the stars move slower off. The lag disappears. I'll link the script.

 var ship : Rigidbody2D;
 var scrollingSpeed : float = 300;
 
 function Start () {
     ship = GameObject.Find("test_ship").GetComponent.<Rigidbody2D>();
 }
 
 function Update () {
 
         transform.Translate(Vector2.up * ship.velocity.y * Time.deltaTime / scrollingSpeed, Camera.main.transform);
         transform.Translate(Vector2.down * -ship.velocity.y * Time.deltaTime / scrollingSpeed, Camera.main.transform);
         transform.Translate(Vector2.right * ship.velocity.x * Time.deltaTime / scrollingSpeed, Camera.main.transform);
         transform.Translate(Vector2.left * -ship.velocity.x * Time.deltaTime / scrollingSpeed, Camera.main.transform);
 
 }

avatar image LaneFox · Jul 01, 2015 at 03:51 PM 1
Share

If you make the planes farther away (using a perspective camera) you will automatically get a parallax effect. This works with the new 2D system as well.

The reason that script is lagging your game is because there are so many stars.

avatar image Destava · Jul 04, 2015 at 10:19 AM 0
Share

It worked man great! After switching to perspective view and putting the plane where the stars are on further back, the lag stopped completely.

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

Attaching a script to a second object ruins everything 1 Answer

'text' is not a member of 'OBJECT' JavaScript Not Working in Unity 3.5 - Lost Commands? 2 Answers

Simple way to make an object go up and down?(Y axis) 1 Answer

Making a ball move towards the mouse? 1 Answer

Enable objects to enter the trigger 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