Hi all, I am trying to acheive a similar effect found here with the background stars. Im only talking about right in the beginning, ie without any parallax effects. just the random generation and infinite size. There is a screenshot of my current attempt, It works by generating 1000 randomly placed stars within a circle of a certain radius, there is a circle collider set as a trigger attached to the player and whenever a star leaves the trigger it gets deleted and and a new star instantiated on the other side of the trigger, which means all stars have to have rigidbodies (as far as i know? ) . This does work but it comes at a serious overhead (especially just being the background) and if the number of stars increases any other 1000 the framerate drops substantially. Can anyone help with ideas on how to achieve this more efficiently?
You'd be better off using Graphics.DrawMesh to render the stars to screen in code, rather than moving 1000s star objects around. This way you can write a function that draws the visible stars from point a (the camera focus) up to range r (the maximum visible range (the corner of the screen to the centre)). I know very little about Graphics.DrawMesh, but this should get you started: http://docs.unity3d.com/ScriptReference/Graphics.DrawMesh.html ating a
How about just placing particle system there? Does the stars (background) need to move or just the player & camera?
@Punchbag Thanks, I will definitely check that out for the rendering. I am still not too sure how i would generate the stars though. @mgear I havent really worked much with the particle system before, The stars will be static (i am thinking about eventually adding in a parallax effect though) But if i do do the infinite space, then i will have to keep the player and camera stationary and move the world. so then the stars will move.
Keep it simple at first, just write an algorithm that says: For given camera position x/y, draw a star at every whole 80 pixels from origin that is on-screen. (that's whole 80 pixels from world origin, not the camera's focus, or they'll move with the camera!) This will give you an endless grid of stars. You can then tweak the formula to have them more sporadically displayed, but still consistently generated.