Take into account that Applying a force is not the same as changing the velocity of the object.
Without friction, the result would be very similar, but when an object is standing in a surface, and there is friction between them, the behaviour could be very different.
In the videos you uploaded, the cube is rolling because you are pushing it from a side, just like a regular cube would roll if the friction was strong enough.
If you want the cube to glide as you say, you have to remove this friction. To do so you must assing a new Phycics material
to your cube, and remove friction from it.
- Create a Physics material
- Select it, and in the inspector, remove friction:
- Assign the new material to the Box Collider
Also, I would highly recommend update Physics behaviour from FixedUpdate()
As for the function to move the object, it should look something like this:
void FixedUpdate()
{
//Moves the character to where it needs.
if (Input.GetKey(KeyCode.D))
{
GetComponent<Rigidbody>().angularVelocity = Vector3.up * deltaMovement;
}
else if (Input.GetKey(KeyCode.A))
{
GetComponent<Rigidbody>().angularVelocity = -Vector3.up * deltaMovement;
}
if (Input.GetKey(KeyCode.W))
{
GetComponent<Rigidbody>().velocity = transform.forward * deltaMovement;
}
else if (Input.GetKey(KeyCode.S))
{
GetComponent<Rigidbody>().velocity = -transform.forward * deltaMovement;
}
}
Notice I'm using velocity
. If you were to use AddForce
, the object would move faster and faster, as you keep applying force to the object.
If you decide to use velocity
, you can rise the material friction a bit if you wish.