Parallax Cameras and Projectiles

I’m currently toying with a top-down space shooter type game that uses multiple cameras and layers to achieve a pseudo-parallax effect. For all but the player camera, I am simply moving the cameras to PlayerPosition * Dampener (.5f for example) along X and Y.

For the player camera, I want a little ‘squish’ to give more feeling of movement. I use mathf.lerp to add some lag time in the camera movement, meaning the player’s ship is not always dead-center on the screen.

The problem with all of this is when it comes time for the player to fire projectiles at something. The target’s camera is rendering from the center, but the player is rendering from off-center. If I render bullets on the player’s camera, they look perfect, but miss the targets because the rendering is off. If I render the bullets on the target’s camera, they hit perfectly, but they look like they’re shooting out of nowhere.

The only solution that’s coming to mind would be to clone the player and have an invisible version on the target camera’s layer that does the real work of shooting and destroying targets. Then the rendered player would just be there to look good.

Please tell me there’s an easier and less crazy way!

“Please tell me there’s an easier and less crazy way!”

I would say it’s incredibly simper to have a STATIC CAMERA and just scroll the backgrounds. Really, I don’t see any reason to do what you describe.

All you need is a really trivial script (something like “move this one panel”) that you just drop on the different BG elements. it would understand the idea of wrapping around at the ends (you’re with me right?) That’s it.

then just have a BG control script (a few lines) that tells each of those what speed to go at, and anything else you want.

regarding multiple cameras. it is extremely common on here to tell beginners “Oh - you should be using multiple cameras for problem _ _ _ it’s a great trick!”

But here, I don’t see any reason you’d use multiple cameras - just use one. it’s a dead-simple setup.

regarding your “phsycis feels” which you nicely describe, just program them in. make a scriptg called “fall back feel” or something that gives that sort of “laggy, moving left” feel you describe (a few lines of code) and drop it on the player (or whatever)

regarding bullets, they should simply be the child, correctly, of whatever is physically meaningful, and then it will all work.

Also FYI there are many “parallax bg” packages on the asset store (I mean it’s only a few lines of code). they are onlya few dollars so buy them all just to see other people’s ideas

finally if this is essentially a 2D game, get 2dtoolkit to save years of effort, and recall that “unity 2D” is coming soon from unity so you will have to reprogarm everything!