Sinks into and comes out regularly

i am new to unity, how can i create a simple movement for an object that don’t sink to other objects while moving?

i’ve add Rigidbody and BoxCollider to them all.

i wrote this and attached them to the object

var s = 5;

function Update () {

if(Input.GetKey (“up”)){

transform.Translate(0,0,s);

}

if(Input.GetKey (“down”)){

transform.Translate(0,0,-s);

}}

The problem is that When the player collisions another object, it sinks into the object a little and if I hold the arrow key down, the player sinks into and comes out from the object regularly.

It leads the camera which is behind the player, to go back and forth regularly.

How do I solve this problem?

Hi!
Dont mix physics with direct transform manipulations!

Replace your transform translate with an equivalent rigidbody.addforce or similar.

Your making life miserable for the physics engine if you move the transform outside of the physics simulation.