Rotating a cube horizontal axis

Hello frieds,

Hopefully someone can help me.
I’m a beginner in programming and i would like to make a easy game.
Where the player has to avoid obstacles that falls from top to bottom.

The player is a cube that can moves to the left and right now its sliding over the ground.
But it seems me better if the cube “rolls”.
Like in this youtube video Game development - Advice for developing a simple mobile game - YouTube

The way i move the player is transform.Translate() and GetAxis(“Horizontal”)

Can someone help me on my way, please?

Hopefully you understand me well.
My English is not very good



You should use the physic engine of Unity to reproduce the example. Indeed, you can easily reproduce bounces and inertia of the cube with the physic engine, but it would be a mess to do that with transform operations.

Instead of using transform.Translate(), you must to attach a rigidbody component to the cube. And In the FixedUpdate() function of the script attached to the cube, you could add something like this:

void FixedUpdate(){
   if(Input.GetAxis("Horizontal") != 0)
      float hAxis = Input.GetAxis("Horizontal");
      Vector3 moveDir = new Vector3(hAxis, 0, 0);
      myRigidBody.velocity = moveDir * movementSpeed * TimefixedDeltaTime;

And after, in the rigidbody component, you can change value of friction, mass, etc, to change the cube behavior.