Ball goes through walls ????

I am new to unity. I am creating a game with ball. I have created a maze with walls(CUBE) surrounded to it. When i move the ball it goes through the walls. I need to fix this. I have used thin box colliders to prevent the ball but still it goes through it. Can anyone tell me the solution for this ? Thanks in advance.

Are you using transform.Translate to move the Ball? Because if you do then it goes through everything since there’s no collision detection in transform.Translate

If you want collision you can use rigidbody, look up rigidbody in the Unity scripting reference

Maybe the collider on your ball or on the wall is set to Trigger.

Have a look at the Unity Roll-a-Ball tutorial if you haven’t already. This provides an example of ball/wall collision in the ‘Creating pick-up objects’ video.

Edit for additional suggestions…

Try setting the Collision Detection drop down on your ball’s Rigidbody to Continuous.

Have a look at the Unity reference material for Rigidbody for more detailed explantion.

I hope that helps!

attach this script to your ball and handle the float values to your needs

Just test it

public float desiredSpeed = 5000f;
public float maximumDrag = 1f;
public float forceConstant = 5000f;
Rigidbody rigibody;

void Start(){

void Update(){
    Vector3 dir =; 
	dir.x = Input.acceleration.x; 
	dir.z = Input.acceleration.y;
    Vector3 forceDirection = new Vector3(dir.x, 0, dir.z);
    //This reduces drag when the player adds input, and makes it stop faster.
    rigidbody.drag = Mathf.Lerp(maximumDrag, 0, forceDirection.magnitude);
    // this reduces the amount of force that acts on the object if it is already
    // moving at speed.
    float forceMultiplier = Mathf.Clamp01((desiredSpeed - rigidbody.velocity.magnitude) / desiredSpeed);
    // now we actually perform the push
    rigibody.AddForce(forceDirection * (forceMultiplier * Time.deltaTime * forceConstant));


I was seeing the same issue and I was able to resolve it by setting “Size” parameters under “box collider” to 1,1,1 instead of 0,0,0 (default).