- Home /
Trying to create grid background and star field
I am working on a game in which I need to have an overhead camera facing down on a ship. I need to have a grid that is drawn that provides a point of reference. The grid needs to not follow either the camera or the player, but rather as a backdrop. Since the ships can travel at considerable speeds and go considerable distances, the grid needs to be able to be either infinite, or at least very large (I could impose a limit on how far the player can go.
Also I need to dynamically generate a star field in the background, I imagine the technique would be similar, it would just be some distance behind the grid layer, and they would probably be multiple star field layers to create a parallax effect.
I'm not sure how to go about this.
I consider myself to be a novice at coding.
Answer by KubaPrusak · Jun 01, 2015 at 04:45 PM
You can fill the camera view with textures of a grid that tessellate. Then you can use this function OnBecameInvisible() Documentation Link to see when the object goes outside the screen. When it does go outside in the BecomeInvisible you can move its position so that when the player moves in a direction the grid is there.
For example
If player is moving right
function OnBecomeInvisible()
{
if (direction == "right")
{
this.gameobject.transform.translate(value that will make it go on the other side of the screen to tesselate);
}
}
This script would go on the grid texture gameobject.
That may work. Now I have to figure out how to display and configure a grid. I'm not sure I want the grid to be a texture though, because if it is, then at differing zoom levels, and on screens with differing resolutions, it might look funny. I'm sure Unity supports what I'm trying to do, I'm just not sure how to do it.
In my game, the camera scrolls with the player, but without some type of backdrop and reference, you really have no bearing on speed or distance. I want to be able to zoom the camera in and out, and the grid provides the visual reference for speed and scale.