ball breaks through walls

Hello. I am new to Unity and I am trying to create my first game. The basic idea is that this is a 2D game on a plane like space invaders. I have one enemy that moves back and forth on the x axis and it shoots down projectiles every few seconds (sphere game object). I want the projectiles to be able to bounce off all 4 walls of the game and keep moving in the game space. The problem is that the balls keep breaking through the lower boundary (All 4 walls have a rigidbody) . They seem to hesitate on collision for a second then break through. Is there anyway I can keep the balls constantly bouncing off the walls? (Like Pong if it had multiple balls and 4 walls instead of 2)

I included the code (Javascript) for my enemy’s movement, and the ball itself (called enemyblast) Thank you for any help.

Enemy Movement:

var enemySpeed: int;
var blast: Rigidbody;
static var moveDir = Vector3.right;

//Launches Projectile on 2 second intervals

InvokeRepeating (“LaunchProjectile”, 2, 2);

function LaunchProjectile ()
{
var instance: Rigidbody = Instantiate(blast,transform.position, transform.rotation);
instance.velocity = Random.insideUnitSphere *10;
}

function Update ()
{
var moveIt = enemySpeed * Time.deltaTime;

//make the enemy move side to side

if (transform.position.x >= 24)
{
    moveDir =   Vector3.left;
}

if (transform.position.x <= -24.0)
{
moveDir = Vector3.right;
}
transform.Translate(moveDir * moveIt);
}

Enemy Blast:

var blastSpeed: int;

//Makes the enemy fire downward

function FixedUpdate ()
{
amtToMove = blastSpeed * Time.deltaTime;

transform.Translate (Vector3.down * amtToMove);
}

Welcome to the forums automan64!

I didn’t run your code, but I think I see the problem with it. You are using transform.Translate to move the bullet. Doing this is a very strict way to move an object that is not based on any sort of collision. Translate ignores the rigidbody and any other component that might have an impact on the movement. I think this is what is causing you problems. Instead of this, take a look at this 1. You need to use .AddForce(Vector3.down*amtToMove) to move rigidbodies around. A good practice is if you find yourself using .Translate to move an object around, take a moment to really make sure that the translation can happen blindly with no concern to anything else in the scene. Your other movements (the enemy ships) look like they are controlled by numeric values in code, the -24 and +24. Those are working well since they have a value hard coded in like that. But… once you fix the bullets, maybe see if you can implement the same sort of solution to their movement