Hello,
I’m having hard times with a simple ball that should stay in the box ,but is falling out for no apparent reason.
The box is rotating with a small velocity.I don’t want to increase the ball or wall size.Funny is that if I shoot the ball in the wall with big force,the behavior is normal and the wall “is solid”.So it must be something with the rotation.I have tried change some parameters (see in code),but no success.All my code is attached to the camera.Please help!
void Start()
{
floor = GameObject.CreatePrimitive(PrimitiveType.Cube);
floor.transform.localPosition = new Vector3(0f, -0.50f, 3f);
floor.transform.localScale = new Vector3(2f, .1f, 8f);
GameObject wall1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
wall1.transform.localPosition = new Vector3(1f, 0f, 0f);
wall1.transform.localScale = new Vector3(.1f, 2f, 2f);
wall1.transform.parent = floor.transform;
GameObject wall2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
wall2.transform.localPosition = new Vector3(-1f, 0f, 0f);
wall2.transform.localScale = new Vector3(-.1f, 2f, 2f);
wall2.transform.parent = floor.transform;
GameObject wall3 = GameObject.CreatePrimitive(PrimitiveType.Cube);
wall3.transform.localPosition = new Vector3(0f, 0f, -1f);
wall3.transform.localScale = new Vector3(2f, 2f, -.11f);
wall3.transform.parent = floor.transform;
GameObject wall4 = GameObject.CreatePrimitive(PrimitiveType.Cube);
wall4.transform.localPosition = new Vector3(0f, 0f, 1f);
wall4.transform.localScale = new Vector3(2f, 2f, .1f);
wall4.transform.parent = floor.transform;
GameObject ball = GameObject.CreatePrimitive(PrimitiveType.Sphere);
ball.transform.localPosition = new Vector3(0f, 1f, 0f);
ball.transform.localScale = new Vector3(.5f, .5f, .5f);
Rigidbody ballRigidBodyb = ball.AddComponent<Rigidbody>();
ballRigidBodyb.collisionDetectionMode = CollisionDetectionMode.Continuous;
ballRigidBodyb.interpolation = RigidbodyInterpolation.Extrapolate;
ballRigidBodyb.angularDrag = 0.0f;
ballRigidBodyb.drag = 0.0f;
ballRigidBodyb.freezeRotation = false;
Collider ballCollider = ball.GetComponent<Collider>();
ballCollider.material.dynamicFriction =0.0f;
ballCollider.material.staticFriction = 0.0f;
ballCollider.material.frictionCombine =PhysicMaterialCombine.Minimum;
}
void Update()
{
floor.transform.Rotate(Vector3.up, 1.5f);
}