Looking Through Walls

Making a third-person camera seem easy, but the hard part is the collision. I’ve done it before, but there was a drawback; the camera won’t revert to it’s original position, and the player’s head pops off the body following it. So there went that. I think making the wall transparent for the camera might make things easy. Here’s the script so far:

{
    public float RotationSpeed;
    public Transform Target, Player;
    float mouseX, mouseY;

    public Transform Obstruction;
    float zoomSpeed = 2f;

    void Start()
    {
        Obstruction = Target;
        Cursor.visible = false;
        Cursor.lockState = CursorLockMode.Locked;
    }

    void LateUpdate()
    {
        CamControl();
    }

    void CamControl()
    {
        mouseX += Input.GetAxis("Mouse X") * RotationSpeed;
        mouseY -= Input.GetAxis("Mouse Y") * RotationSpeed;
        mouseY = Mathf.Clamp(mouseY, -45, 10);

        transform.LookAt(Target);

        Target.rotation = Quaternion.Euler(mouseY, mouseX, 0);
        Player.rotation = Quaternion.Euler(0, mouseX, 0);
    }
}

If anyone’s got an idea or two, I’d be happy to hear it.

What are you having trouble with specifically?

What I did in one of my games was have a “desired position” that sits behind the player where you want the camera to sit. In Update, raycast from the player to the “desired position”, if something is hit, the camera goes to that hit point, otherwise, it goes to the desired position.

This means the camera would zoom in if you had your back to a wall for example.

When I tried a tutorial for the camera it worked so far, then came a snag. For one, the camera wouldn’t zoom out and the head of my character popped off. It was literally attached to the camera. Although I forgot to put that in the script you see here. To put it simply, the character is literally a snowman, Two spheres making up one character.