How to Roll a Rigidbody Cube one step?

Hi.
I’m trying rolling a cube with Horizontal inputs.
i used “AddTorqe” , but after a while its flying in the air. i don’t want that.
i want to roll a cube like its heavy (not too heavy) and step by step.
and when its in the middle of rolling to the right , its turn back when i press left key.
and when i release the keys in middle of rolling, physics push it to the correct direction.
72006-box.jpg
i’m using this code. but no luck:

using UnityEngine;
using System.Collections;

public class rotate : MonoBehaviour {

	public float torque = 100;
	public Rigidbody rb;

	void Start() {
		rb = GetComponent<Rigidbody>();
	}
	void FixedUpdate() {

		float turn = Input.GetAxis("Horizontal");
		rb.AddTorque(transform.up * torque * turn);
	}
}

maybe code is good, but not the other setting like (torque , gravity, Mass , Drag , Angular Drag…).
i don’t know.

Any help will be appreciated.

2 Answers

2

A quick and dirty solution is to add a physics material to the cube and increase the physics materials friction property.

Unity Doc: Physics Material

Thanks . that helps. but still dosn't feel like its heavy. its rolling fast and when its do rolling a while, some times its get airborne. adding material friction is improve physics but increasing any of frictions dosn't affect anything.

Here’s a short Youtube video that covers exactly how to roll a cube on its edges: How to Move a Cube by Rolling it | Unity Tutorial - YouTube


rolling cube