Move rigidbody cube without it tumbling
I've got a cube as a player, that I want to move around on top of a larger cube. The cube has a rigidbody as I want it to tumble and fall off the edge if you get too close. I'm using AddForce() to move the cube around, but for some reason it tumbles as it moves, and I don't want that to happen. I want it to slide effortlessly over the surface.
I don't want to constrain the axis, because I want it to tumble and fall. So how else can I stop it from tubling, is this because my drag is too high? I don't want the drag too high or it will be too slippery.
The stats are:
Mass: 20
Drag: 1
Angular drag: 0.1
Here's how I move the cube forward:
GetComponent.<Rigidbody>().AddRelativeForce (Vector3.forward * 20, ForceMode.Impulse);
Answer by melazzeh · Jan 05, 2021 at 08:23 AM
Freezing rotation on X, Y and Z will do the trick. No code required.
Answer by beppim · Nov 28, 2015 at 02:29 PM
Five solutions :)
You can try by changing the physics material of the colliders, so it feels not just "less" drag, but different. In the standard assets there are some examples, maybe "metal" could be good for you. With P.M. you can differentiate between dynamic and static friction.
The second idea that came into my mind is to check that the force to move the cube is applied ON THE BOTTOM of the cube (actually applied force must be below the center of mass, so below 0.5 of the height), so that it should not rotate while pushing. That is the cleanest soution imho.
One more solution: apply a huge angular drag.
One idea also could be to put a fixed collider on top of it, as a sort of invisible ceiling, that avoids the cube to rotate.
Otherwise, there's no real solution to defeat physics when you want and make them present when you want: you can simply move the cube using transform.Translate(), so you won't apply a real force and it won't use physics until it will fall down.
Hmm, I could use Transform.Translate() but won't that mess with the physics of the rigidbody? I've been told not to use Translate on rigidbodies.
I believe that there's no problem in using translate on rigidbodies. Of course, you're applying a sort of "magic" movement and therefore the physics won't be realistic (for example, the movement will stop immediately, without inertia), but that won't create real problems, besides a slightly unrealistic effect. You should not use translate on rigidbodies if you don't want physics to be bypassed.
I like your idea of applying the force at the bottom of the object - that makes sense! Although I've no idea how to apply relative force at a specific position! I seem to have to choose between using AddRelativeForce() or AddForceAtPosition() !!
The force is applied to the center of mass of the collider (not of the object).
http://docs.unity3d.com/ScriptReference/Rigidbody-centerOf$$anonymous$$ass.html
You can edit its position, if you don't it will be calculated.
Ooh, this is interesting, I didn't realise I could do this. I'll try it tonight and let you know!