I am quite new to Unity so please excuse my basic question.
I have created a box and applied a ‘Translate’ script to it so that it moves randomly. I have created a wall of cubes around the playing screen and I want the cube, when moving randomly to bounce on the walls and change it’s direction. I applied rigid bodies to the walls and constrained them but I only had a box collider on the cube which moves randomly but the cube just goes through the walls.
Do I have to write a script for this or can Unity do that by itself? How would the script go like if I have to do that?
You have it backwards—put rigidbodies on objects that move; static objects don’t need rigidbodies. If you use physics instead of manually using Translate, then you will get behavior such as bouncing off obstacles automatically.
Keep in mind you don’t need a rigidbody for an object to have collision, just a collider is enough. Like a box,sphere,mesh etc collider. A rigidbody is for an object you want to react/move when it hits those colliders.
Also keep in mind that using “translate” to move an object won’t respect physics in the way you might be expecting, you’ll need to apply force to the object to move it in order for physics to work.