How to stop a camera clipping through walls?

So I’m making an FPS style game but I can’t quite figure this out. I’m just using the camera as the player’s view, as it was going to be hard to use a character model to do it. I’ve looked on a bunch of other posts, but couldn’t quite figure out how to do it when I’m using translate as opposed to rigidbodies or character controllers.

Here’s my player controller script:
void Update()
{
forwardInput = Input.GetAxis(“Vertical”);
horizontalInput = Input.GetAxis(“Horizontal”);
mouseX = Input.GetAxis(“Mouse X”);
mouseY = Input.GetAxis(“Mouse Y”);

        if(transform.position.y < yBound || transform.position.y > yBound)
        {
            transform.position = new Vector3(transform.position.x, yBound, transform.position.z);
        }

        transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput);
        transform.Translate(Vector3.right * Time.deltaTime * speed * horizontalInput);

        transform.Rotate(new Vector3(-mouseY, mouseX, 0));

        float z = transform.eulerAngles.z;
        transform.Rotate(new Vector3(0, 0, -z));
    }

Would it just be easier to use rigidbodies or is there a way to do this by adjusting the transform?

Hey,

Check this tutorial series out. Even if it’s not exactly what you want to create, you’ll learn some sweet tips - Unity 3D Multiplayer FPS Tutorial 01 - Setup & Motion - YouTube