Child rigidbody clipping through walls.

I am trying to create a gravity gun like in Half Life 2. The gravityGun script parents a cube to the main camera. The main camera is parented to the player. The player is a character controller.

My problem is that the cube passes through objects if the player walks into the wall. This is my Player Controller script. Can someone help me with this problem by ether stopping the player from moving forward or rotating the cube if it is colliding with a wall or moving the cube around in your hands much like in Half life? I should mention that the cube is a Rigidbody.

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(CharacterController))]

public class firstPersonController : MonoBehaviour {
	
	public float movementSpeed = 10;
	public float mouseSensitivity = 2.5f;
	public float mouseVertRange = 60;
	public float jumpVelocity = 5;
	
	private float verticalRoatation;
	private float verticalVelocity;
	private float forwardSpeed;
	private float leftRightSpeed;
	private float rotateLeftRight;
	
	private Vector3 movement;
	
	private CharacterController characterController;
	
	// Use this for initialization
	void Start () {
		characterController = GetComponent<CharacterController>();
	}
	
	// Update is called once per frame
	void Update () {
		
		// Horizontal Rotation
		rotateLeftRight = Input.GetAxis("Mouse X") * mouseSensitivity;
		transform.Rotate(0, rotateLeftRight, 0);
		
		// Vertical Rotation
		verticalRoatation += Input.GetAxis("Mouse Y") * mouseSensitivity;
		verticalRoatation = Mathf.Clamp(verticalRoatation, -mouseVertRange, mouseVertRange);
		
		Camera.main.transform.localRotation = Quaternion.Euler(-verticalRoatation,0 ,0);
		
		// Jumping
		if (characterController.isGrounded){
			verticalVelocity = 0;
			if(Input.GetButtonDown("Jump")){
				verticalVelocity = jumpVelocity;
			}
		}
		
		// Movement
		forwardSpeed = Input.GetAxis("Forward / Backward") * movementSpeed;
		leftRightSpeed = Input.GetAxis("Left / Right") * movementSpeed;
		verticalVelocity += Physics.gravity.y * Time.deltaTime;
		movement = new Vector3(leftRightSpeed, verticalVelocity, forwardSpeed);
		movement = transform.rotation * movement;
		
		characterController.Move(movement * Time.deltaTime);
		
	}
}

you could create a function that determines the cubes velocity, and then applies a degraded amount of velocity to the cube in a direction based on the angle of impact.

This involves some of the trickier parts of Unity. CharacterControllers really hate having childed colliders, and adding rigidbodies, etc… just makes them madder. Lots of questions here about players carrying stuff.

Simplest might be to not child to cube and put it on a spring (attached to an empty in front of the player.) Attaching a spring during play isn’t super-easy, but UAnswers has some things on it. Could start with one cube attached, just to see how it looks. Adjusting the spring settings to look good is also not super-easy.