Hello there, I’m making a Box pick up script and I’m having some issues with making the box collide with stuff. ( Screen capture - 21ddc772244ee938765d08a677df9c93 - Gyazo ) I want it to collide with the walls and other boxes. my code:
public class BoxScript : MonoBehaviour
public Transform Box;
public Transform Player;
public Transform BoxPosition;
public Transform Map;
public bool isHolding = false;
public int maxDist = 5;
private void OnMouseOver()
if (isHolding == false)
if (Vector3.Distance(Player.transform.position, Box.transform.position) < maxDist)
isHolding = true;
Box.GetComponent<Rigidbody>().isKinematic = true;
Box.position = BoxPosition.position;
Box.parent = BoxPosition;
private void Update()
if (isHolding == true)
isHolding = false;
Box.GetComponent<Rigidbody>().isKinematic = false;
Box.parent = Map;
Well I don’t exactly know why this is happening(my best guess is that it has something with your player controller script to do), but I have a workaround to not make it visible that the cube clips through walls for the player.
Make a new Layer, and call it pickedUpCube or soemthing like that.
2)In your pickup script assign the layer to the cube everytime you pick up the cube.
Box.gameObject.layer = idOfPickedUpLaye
And when you drop the cube again, make sure the layer gets set back to whatever it was before.
Box.gameObject.layer = 0;
On your main Player camera remove the “pickedUpCube” layer from its culling mask.
Add a new camera give it the same position your main player camera has, and make it a child object of it.
Set the Clear Flags value of the new camera to Depth only, and set its Culling Mask to the “pickedUpCube” layer, also make sure to remove all the othere layers from its culling mask.
If it doesn’t work, try changin your Depth value on your main camera to 0 and 1 on your new camera.
Now the cube will probably still clip through walls but it won’t be noticeable for the player anymore.
Hope this helps