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 Siccity · Mar 26, 2014 at 10:43 PM · generationspaceplanetinfinitechunks

Random generated debris in empty space

So I'm building a simple space game. Basically you're able to float around at absolute freedom without any drag or gravity.

Here's how it works:

  • I use rigidbody.AddForce to propel the player forward.

  • When player gets further than 100 units from the center of the map, he, and every object is teleported back, seamlessly keeping him in the center of the map to avoid floating instabilities at extreme distances while maintaining the illusion of infinite space.

  • At the beginning of the level, a lot of debris models with rigidbodies are spawned within a radius of the player.

  • Certain events in the map delete all current debris floating around, and randomly spawns some new ones in a radius around the player.

  • The debris is in constant movement, and allows the player to bump into it, changing its and his velocity and rotation.

Here's what I want:

  • When the player moves into an unexplored area, i want a script to automatically populate that area (within a large radius of the player. 1000 units to be exact) with debris from an array. If the player should return to an already populated area, the script should do nothing.

I thought about using chunks like most games with infinite worlds, but I've got no clue how to implement it.

Note: I write in C#.

Comment
Add comment · Show 1
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 Lo0NuhtiK · Mar 26, 2014 at 11:29 PM 0
Share

Note: I write in C#.

Better get on it then.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by initTechsuport · Mar 26, 2014 at 11:26 PM

the most efficient way would to be randomly generating the debris using a pool system, where you re use the objects you started with, and basically change their position and visibility.

but if your not worried about efficiency, using the chunks through LoadLevelAdditive, then having the new part of the level you loaded moved into place along with the character.

if this system is meant to specifically bypass getting floating point inaccuracy, try having the charachter stationary and only mess with his rotation, while instantiating, moving and destroying the debris instead of moving the character.

also scaling things down and lowering the speed lets the player seem to travel a lot farther while only moving a fraction of the distance.

Comment
Add comment · Show 2 · 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 Siccity · Mar 27, 2014 at 07:27 AM 0
Share

I don't care about efficiency at this point. As far as I know, LoadLevelAdditive is a pro-only feature which loads an already set up scene without clearing the current scene. This is not what i need, i need to generate debris around the player where there is none. The floating point system works flawlessly and does not need to be tampered with.

avatar image initTechsuport · Mar 29, 2014 at 02:24 PM 0
Share

sounds like your looking for specific code

 using UnityEngine;
 using System.Collections;
 
 public class BossAssScript : $$anonymous$$onoBehaviour {
     public Transform player;
     Vector3 startPos;
     float distanceTracker;
     public float $$anonymous$$Dist;
     public Transform debris;//thing to instantiate(spawn)
     public int density;//amount of things to spawn
     public float spawnRange$$anonymous$$ultiplyer=.5f;//
 
     void Start(){
         if(player){
             startPos=player.position;
             SpawnStuff();
         }
     }
 
     void Update(){
         if(player){
             distanceTracker=(player.position-startPos).magnitude;
             if(distanceTracker>=$$anonymous$$Dist){
                 startPos=player.position;
                 SpawnStuff();
             }
         }
     }
     void SpawnStuff(){
         for(int i=0;i<density;i++){
             Vector3 randPos=(new Vector3(Random.Range(-$$anonymous$$Dist,$$anonymous$$Dist), Random.Range(-$$anonymous$$Dist,$$anonymous$$Dist), Random.Range(-$$anonymous$$Dist,$$anonymous$$Dist)))*spawnRange$$anonymous$$ultiplyer;
             Transform tingy = Object.Instantiate(debris, player.position+randPos, Quaternion.identity) as Transform;
             //do other stuff to thingy
         }
     }
 }

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

22 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

Related Questions

Mapping Cube to Sphere - Using 64 planes as a cube "side" 1 Answer

[C#] 2D infinite Terrain Generation with prefabs?! -> lag 0 Answers

How can I go about creating an "Infinate" asteroid field?? 1 Answer

loading planets/ rendering distances (KSP planet) 1 Answer

how can i make an infinite map using tilemap and also making chunks 0 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