Collisions when pushing object

Hi,

Im having some problems with collisions hope someone can help!

I have a gameobject which i instantiate and the user can move around with the arrow keys, which I have coded as below:

if (Input.GetKey(KeyCode.UpArrow))
transform.Translate(new Vector3(0,0,1) * Time.deltaTime, GameObject.Find(“Main Camera”).transform);

Im having problems that when the item is being moved around it is going through walls etc, I have a rigidbody and colliders on the walls and the moving object. Clearly im doing something wrong, can someone tell me what im doing wrong?

This also appears to be happening if I use rigidbody.Addforce, with the added fun that doing it that way means i cant stop it moving!

  • As said in comments, Transform modification don’t care about physic. Use AddForce (and co) or a character controller.
  • The main cam is accessible through Camera.main, instead of using Find, which can give you performance loss with a lot of objects.
  • Use Vector.forward instead of new Vector3(0,0,1). It’s not important, but it makes the code more clear.