collision not working (i'm new)

i have a cube with the code
void Update()
{
transform.Translate(Vector3.forward * Time.deltaTime * 20);
}
and i also have a wall that a want to collide with the cube and the cube just goes through the wall. Both of the objects have rigidbody’s and box colliders.

Your cube will need a Rigidbody on it and you should be using the Rigidbody MovePosition method to move the object in the FixedUpdate. Using Transform Translate will teleport the object to the new position, MovePostion moves the object there respecting any colliders in the way.

You cannot modify the position of the object via the Transform component directly if you need it to interact with physics colliders. For that, you must use a Rigidbody/Rigidbody2D component to move the object.

See:

Thank you!