[Resolved] Scrolling camera makes everything disappear (2d shooter)

Hey there
I’m trying to make the camera scroll upwards continuously in my 2d shooter but I’m getting a blank image in the ‘Game’ window.
What’s weird is that the camera appears to scroll correctly in the ‘Scene’ window i.e. the white rectangle moves up my background, it’s just that I’m not getting a feed, and this happens for the entirety of the runtime process.

Here’s how I scroll the camera:

    public float scrollSpeed = 5;
    void Update()
    {
        float bkHalfWidth = transform.position.x;
        float bkHalfHeight = transform.position.y;
        transform.position = new Vector3(bkHalfWidth, scrollSpeed * Time.deltaTime + bkHalfHeight, 0);
    }

^^^This component is connected to the main camera object.
Any feedback would be appreciated

You’re setting your camera’s Z-position to 0. This might mean that the camera is adjacent to the game scene and is unable to see everything.

Instead of:

transform.position = new Vector3(bkHalfWidth, scrollSpeed * Time.deltaTime + bkHalfHeight, 0);

try:

transform.position = new Vector3(bkHalfWidth, scrollSpeed * Time.deltaTime + bkHalfHeight, transform.position.z);

Hope this helped :slight_smile:

That was it thank you!

I saw that the camera’s z pos was -10 in the inspector but couldn’t make the connection