- Home /
A question about colliders, or why does my cube go through other cubes when they are constrained?
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?
Answer by Eric5h5 · Jul 14, 2013 at 08:56 PM
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.
Answer by ALLCAPS · Jul 17, 2013 at 04:13 AM
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.
Your answer
Follow this Question
Related Questions
physics.OverlapSphere colliders 1 Answer
Question Local Translation PRoblem 2 Answers
Trying to translate a game object a fixed distance 3 Answers
Can't move instantiated prefab 2 Answers
Transform translate 1 Answer