Position of a falling cube
I am trying to learn a bit of 3D game programming with Unity and I have a rectangular flat base. I am trying to spawn some cubes that fall from the sky and I want them to stop moving when they touch said base. The cube size is (x, y, z) = (1, 1, 1) and the box collider's properties are center: (x, y, z) = (0, 0, 0) and size = (x, y, z) = (0.9, 1, 0.9).
When I pres play, the cubes fall as expected, but when they collide with the ground they stop at a height of 0.957... and if a cube falls on top of another cube it stops at a height of 1.923... I had expected them to get heights of 1 and 2 respectively, since everything's height is 1. Why is this happening? To stop the blocks from moving (because they bounced before I did this) I have this code:
private void OnCollisionEnter(Collision x){
rb.velocity = new Vector3(0.0f, 0.0f, 0.0f);
rb.isKinematic = true; //Because I don't want them to be affected by physics anymore, they just become a part of the ground.
You said you set the box collider to 0.9. Wouldn't the collider be smaller than the cube then?
Hey! Thanks for your reply! I had thought about it, but the collider is only 0.9 size along the x and z axis (so width and depth). Heightwise it's 1. I even tried changing it to (1, 1, 1) but I had the same problem...
Maybe instead of writing code for the bouncing, you can add a physics material to the colliders and set the bouncing to $$anonymous$$imum. You can create one by right clicking in assets and looking under "Create", and then adding it to the collider. They would still topple over though... How much of a difference would the collider bug make to your project?
Wait... you said you had a rectangular flat base? What are the dimensions of it?
Your answer
Follow this Question
Related Questions
How to make a cube shrink over time 2 Answers
Gravity on a cube planet 1 Answer
How to stop jitter on rigidbody? 0 Answers
Enable / Disable Gravity on Cube World 0 Answers