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 JezerJojo · Feb 16, 2013 at 03:32 PM · c#prefabprefabsinfinite

How to create meteors everywhere without making the game slow?

I am new to the community. I had by accidently made a thread on this on http://forum.unity3d.com/threads/170642-Meteors So here's what I had written... I have a controllable jet which constantly moves, and I want to make meteors everywhere. I have a prefab of the meteor. Of course I can't make gazillion meteors everywhere in the scene, so I am planning to make new meteors appear in front of the jet and the meteors behind the jet to just get destroyed. How do I do this? The jet must be able to crash in on the meteors. I normally do code in C# but UnityScript (JavaScript) is fine...

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 robertbu · Feb 16, 2013 at 04:36 PM

There is a lot you can do. You are on the right track by have a limited number of meteors and moving and moving them in front of the jet. To determine if an object an be destroyed I would first check if it can be seen by the camera. There are a variety of ways: Take a look at the following. OnWillRenderObject, Renderer.isVisible, Renderer.OnBecameVisible, and OnBecameInvisible.

From this list of not visible meteors, I'd cull any objects that are unlikely to be seen and place them in front of the camera. Convert their positions to Viewport coordinates (Camera.WorldToViewportPoint()) Points that can be seen with have x and y values in the range of 0 to 1, and a positive Z value. Anything with a negative z value will be behind the camera. Anything with a value far outside the 0 to 1 range is highly unlikely to be seen by the ship even if it is turned somewhat.

You can use Viewport coordinates in placing the meteors to assure that they will be in or near the field of view.

As for making the meteors display efficiently, take a look at this page:

Draw Call Batching

There are limits (such as mesh complexity) to what can be batched, but when it usable, speed improvement can be substantial.

Comment
Add comment · Show 4 · 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 JezerJojo · Feb 16, 2013 at 07:01 PM 0
Share

Thanks robertbu!!! I thought about the OnBecameInvisible() {/ Destroy object Script/} But if I turn the ship 90 degrees in the game will there be any meteors seen? how do I make the x, y and z coordinates of the meteors random between the viewport in the axis (not including the other 2 axes) from the ship without making them collide? By the way I didn't understand the Draw Call Batching, I'm just 11 years old. Thanks a lot!!!...

avatar image robertbu · Feb 16, 2013 at 08:10 PM 0
Share

Congrats on being 11 and tackling coding a project like this.

In order to make suggestions, I need to know a bit more. What is moving in the scene, the meteors? The ship? How are things moving (i.e. you are moving them through the transform, or are you using Rigidbodies and force)? What is your target platform (PC, Web, mobile). The ship can obviously turn. Can it turn a full 360? And is this first person or third person?

avatar image robertbu · Feb 17, 2013 at 04:13 PM 0
Share

A few things to mention since your original question was about performance. I don't know what you used to model your meteor, but if your meteor (technically I think they are asteroids) can be kept simple enough, and if you use the same material for all your meteors, then the drawing of the asteroids will be batched together by Unity. The limit is 900 vertex attributes in total, which usually means 450 to 300 vertices. You can see major performance improvements by having Unity batch object together. Select your mesh in Unity, and it will tell you how many vertices and triangles are in the mesh.

As for your destroy code. I would create all my meteors at the beginning of the game, and never destroy them. I'd just move them. I'd check that both the distance is too long and that it is not visible. If the the meteor is visible, it is likely your ship is moving in that direction. At the top of my meteor script, I'd initialize a variable in Start() (assumes the name of the game object is "Ship"):

 goShip = GameObject.Find("Ship"); 

Then inside update you can check:

 if (!renderer.isVisible)
 {
     float dist = Vector3.Distance(gameObject.transform.position, goShip.transform.position);
     if (dist > /* some number */)
     {
     // $$anonymous$$ove the ship.
     }
 }
avatar image JezerJojo · Feb 18, 2013 at 11:30 AM 0
Share

Thanks a lot robertbu !!! Now I can make my game properly.

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

10 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

Related Questions

Multiple Cars not working 1 Answer

How to tell at runtime if a GameObject is a prefab 3 Answers

Link GUIText to a prefab? 2 Answers

Insert a prefab into scene in a script? 1 Answer

why all my prefabs get destroyed whem i destroy one of them,Why all my prefabs get destroyed whem i destroy one of them 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