- Home /
Creating Objects and Hiding when out of Range
Ok so I want to work on a basic game and make the world out of cubes which I manually create the maps with for loops. Problem is that after 40x40x40 fps gets unstable going from 30-50fps. I asked around and everyone suggested using triangles and blah blah blah. It's way more complex than I want and can understand. So I decided to only create levels when my player.transform.position.y is less than a point. It works great! But how can I make certain areas non visible when my position is a certain point? Can anyone provide some visual code examples? Feel free to add to my code seen bellow.
bool addlevel3 = true;
public GameObject player;
public Transform packIce;
public Transform Ice;
void Awake()
{
for (int x = 0; x < 40; x++)
{
for (int y = 0; y > -2; y--)
{
for(int z = 0; z < 40; z++)
{
Instantiate (packIce, new Vector3(x, y, z), Quaternion.identity);
}
}
}
iceSpike();
}
void Update()
{
if(player.transform.position.y < 1 && addlevel3 == true)
{
addlevel3 = false ;
for (int x = 0; x < 40; x++)
{
for (int y = -2; y > -3; y--)
{
for(int z = 0; z < 40; z++)
{
Instantiate (Ice, new Vector3(x, y, z), Quaternion.identity);
}
}
}
}
}
Dude why do you need Instantiate 3200 Objects??
And then again, another 4800?
It's for a $$anonymous$$e craft style game for a little fun and I want a basic way of increasing fps hints the above. I don't know just a little project I suppose.
What exactly are you trying to achieve. If you want help in achieving a solid goal, a little more background information might be useful. The way your going about it right now seems to me to be all wrong, your FPS problem is very apparent in its cause.
You cant just Instantiate the entire world all at once. If you look at $$anonymous$$inecraft when it loads a new world, it generates large chunks of the world 1 at a time, not all at once, if it did it all at once it would run into the same problem your having. You need to break up the Generation of your world into manageable chunks and then load them at appropriate times. This will reduce the impact on your system resources and smooth out overall frame rate.
Voted this question up, but bear in $$anonymous$$d this question could have different correct answers, and is mostly intended for discussion of best practices, you could post it in the forums ins$$anonymous$$d in order to receive more ideas. If you have received an answer to your original question please mark this as [SOLVED] or answer it below, so we can move it out of the Unanswered view and give more relevance to other questions requiring attention. Thanks for your comprehension, Unity Support.
Answer by unimechanic · Feb 24, 2014 at 11:38 PM
It's for a mine craft style game for a little fun and I want a basic way of increasing fps hints the above. I don't know just a little project I suppose.
You can read the basics of building a Minecraft style world here:
http://forum.unity3d.com/threads/192954-CoreDev-Creating-Voxelised-Worlds-(Like-Minecraft!)
Your answer
Follow this Question
Related Questions
Custom Inspector, duplicates variables ? 1 Answer
hide button 1 Answer
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
How to instanciate transform to element of a list?,How Get Transform of a instanciated Prefap 3 Answers