- Home /
How would I go about making a cube "tumble" off of corners and such?
Title says it all. I have a simple cube on a desk. I would like it when i move the cube (Trough keys atm) it falls, but not directly downward, but tumbles around and when it hits the ground it tumbles more until it steadies. All the while the camera is steadied. IE, its not tumbling as well. Any way of attacking this feat? Any help would be great!
--Dove Devic
Answer by Freaking-Pingo · Nov 02, 2013 at 11:52 AM
From my understanding it sound like you want physics implemented into your game. Add a rigidbody to your cube and use .AddForce() for handling movement. The physics in the rigidbody will make sure your cube falls of the table.
You should properly dwell into the physics system a bit in order to understand what you are actually doing and therefore I have linked a few resources for you.
Answer by Owen-Reynolds · Nov 02, 2013 at 04:34 PM
Assuming you are using a rigidbody, but it looks kind of boring when it falls:
o A physics material can give it more bounce, or change friction (sometimes giving it more friction will make it tip over and roll more, instead of sliding.)
o Changing the collider can make it roll more. Could make your own cube mesh but with rounded corners (if you don't know how to model, this will be too much trouble, unless you can find one premade.) Or, easier to do but harder to explain, you could shrink the box a little and add a capsule collider (child) along each edge. That will make them count as rounded.
o Can give the cube a script with OnCollisionEnter. Say something like "if it's going fast enough, give it a fun twist and bounce." Ex:
if(rigidbody.velocity.magnitude>2.0f) { // going fast enough
// sample twist (other ways to do it, but this does work):
rigidbody.angularVelocity += new Vector3(Random.Range(-2.0f, 2.0f),0,0));
// sample jiggle:
rigidbody.velocity += new Vector3(Random.Range(-0.5f, 0.5f), 0, 0);
}
This can take a lot of tweaking to make it not just bounce around like popcorn.
o Put some invisible, small colliders where it will land. Say you add a long flat tilted (invisible) cube. If it's close enough to the ground, no one will notice you're hitting something invisible. And it will pop your cube a little bit sideways. Adding some more small "point up" invisible cubes will twist your cube when it hits them off-center.