I have a game where the player is able to move infinitely. How would I make it generate a prefab planet and asteroid but when you get far away from the "terrain" they unload so the game works well. - Sort of like the game minecraft.
I'm not sure if occlusion culling would help, ofcourse it's a good tool but it expects the scene to be fully constructed and baked before runtime if I'm not mistaken? I would create a class that check the distance between the camera and the chunk once a second or so, if the distance is far enough I would disable the chunk and Place it in an object pool. There's probably a much better way to solve it though, but not that I know of myself. >,<
Thanks for the reference but that's not exactly what i'm looking for. I need to actually disable the object because I have some scripts that start to dramatically lower the FPS. That would just be the renderer - right? If i am mistaken sorry
Just one question. I have no idea where to start writing this script (sorry) but what is an object pool?
you could do something like this: it needs your player to have the tag "Player" and your planets the tag "Planet" Code (CSharp): using UnityEngine; using System.Collections; public class DeactivateByDistance : MonoBehaviour { public float distanceThreshold=10; //low number for testing purpose, you could set this to your camera's far plane. private GameObject[] planets; private GameObject player; void Start() { player = GameObject.FindGameObjectWithTag("Player"); planets = GameObject.FindGameObjectsWithTag("Planet"); } void Update() { foreach (GameObject planet in planets) { if((player.transform.position.magnitude-planet.transform.position.magnitude) > distanceThreshold) planet.SetActive(false); else planet.SetActive(true); } } }
At the moment I''ve too Little time to explain in depth, but here's a link to a video explaining some basic object pooling: http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-pooling Object pooling is quite common in game design so if you google for it you should surely find some matches on even more documentation and tips aswell.
Thanks jister but would I put this on an object like the main camera or should I put it on something else? Also to put multiple things to get spawned with different rarities - How would that work? EDIT This doesn't spawn the planets randomly - how does that work?
if you want to do voxel terrain(planets) check out these tutorials: http://forum.unity3d.com/threads/tutorial-procedural-meshes-and-voxel-terrain-c.198651/ the script i posted you can hang on an Empty GameObject. and when finished generating you planets, put them in a parent tagged as "planets"...
Thanks a lot! Any Idea how I would make this 2D Voxel terrain though. I searched it up and couldn't find anything.
do a search on the tutorial page for 2D... it's the same principle only use quads instead of cubes...
Could you do show me something to follow that's meant to be 2d please? I'm very bad with code so sorry though And I also want to have some space inbetween planets. Like solar systems. Any chance i could use a prefab insteas of a cube?
is your game 2D or 2.5D? are you going to use sprites and stuff or just an orthographic camera? if it's the second you just follow along with the tutorial, I recommend just doing the tut as is and once finished do it again and adapt to your needs. but i've you have that little experience maybe you should first learn to code better before starting on such advanced stuff. why not make your game a bit smaller and not generate a universe procedurally?
My game is 2d and has sprites. I know how to code in java so i figured I would try c# or JS. JS turned out to be pretty weird so I am adapting to c#.
It sounds like you're in a bit over your head. Start smaller to - if nothing else - get a grasp of Unity's workflow and structure. Check out the Learn section, then come back and ask lots of questions
Learn. Also don't bump posts. Also here's the first video in a great series on how to make your first game project.
It's linked at the top of this page, right next to the Community link. Quite frankly - it's troubling that me mistyping the word Learn (despite typing it correctly in a previous post) held you up for three days. It gives the impression that you're not willing to take the initiative when it comes to learning and understanding the concepts necessary for this type of work. Everyone here is willing to help you, but you have to put in the legwork yourself first. If you don't want to do that (and that's perfectly ok!) then head over to the Collaboration section and try to find someone to work with.