- Home /
Scrolling Skybox with a 2D space shooter
I'm developing a space shooter, 2D top down.
I have two cameras, one main and one background. The main camera is rendering everything but the background itself, having a depth of -1, and is orthographic. Clear flag is 'depth only' The background camera, I'm using a perspective camera (Not sure if this is right but looks better atm.), depth of -2, only renders the background itself.
My camera follow script and background follow script is this, attached to the main camera is this:: if (target)
{
Vector3 point = camera.WorldToViewportPoint(target.position);
Vector3 delta = target.position - camera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, point.z)); //(new Vector3(0.5, 0.5, point.z));
Vector3 destination = transform.position + delta;
destination.y = 10;
transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, dampTime);
if (bgCamera)
{
bgCamera.transform.eulerAngles = new Vector3(-transform.position.z % 360, transform.position.x % 360, 0.0f);
}
}
bgCamera being the background camera. Target is the space ship.
Now, traveling 'one direction' seems to work (even though it feels like it's in a sphere, but that's another issue), but when mixing in both it gives a wierd look, the angle gets all wierd. I've supplied a youtube video to show it. First one is flying straight up, works okay, then flying left, works okay.. Mixing in both, doesn't work.
https://www.youtube.com/watch?v=jnSYS39QA0U
Overall I'm not sure if the skybox is the best approach or if there is a better idea. I 'really' like the skybox program I am using right now as it generates very nice skyboxes. But I want the background to seem 'endless' and skyboxes seem like a way to go.
Answer by Conroy100 · Dec 09, 2014 at 01:48 AM
I am having the exact same problem, however, i'm only using a skybox image on my +z plane which always flollows the main camera, and a sphare particle system that follows the player and rotates in the opposite direction of the player. i don't know how to fix it, but i'm wondering if i could just create a flat particle system that follows the player, creates new particles on the edge of the player field of view, then destroys particles that are too far from the players perspective.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Rotation problem 1 Answer
Minimum distance on configurable joint? 2 Answers
2D Game - Y axis rotation (left - right) 2 Answers
Is possible to keep running code in phones while application is backgrounded? 1 Answer