Create example cs and change the script code to that shown below.
How to make something not go through floor unity.
Attach the script to any object that might move fast enough to go through other colliders.
Make sure that the layermask does not include the layer of the object the script is attached to otherwise the object will collide with itself.
Moved initialization to an init method to make the script more usable if added through script.
A floor object is created for you.
Thank you for helping us improve the quality of unity documentation.
Although we cannot accept all submissions we do read each suggested change from our users and will make updates where applicable.
One of the challenges i ran into was that when the player moved above a certain velocity it would sometimes pass through colliders.
To view this example create a new 3d project and create a cube placed at the origin.
Quick demo of more usages of getcomponent to change boxcollider trigger status and rigidbody gravity scale.
Recently i have been working on a 2d platformer which uses the inbuilt unity physics and rigidbodies.