Andrew Lawmaking Andrew Lawmaking - 1 year ago 75
C# Question

i want my cube will not extend through the ground.How to do this?

I have a ground and a cube, both have rigidbody and colliders. My cube is situated upper than my ground. I did management by cube using keys(for example i press 'S' and my cube fall down on 1). The problem is than my cube touches ground and i press 'S' it extends through my ground. Who knows how to solve it?

Answer Source

well...a simple solution can be to set a min value on that axis for the cube. for example, something like that:

if(Input.GetButton("S")) //move object when u press S
     if(cube.y > ground_y)  //in this way your cube can move only if it's over the ground  
     <your code to translate the cube>

so if your colliders fail for some reason you have an additional check.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download