Search code examples
unity-game-enginerotationphysicscuberigid-bodies

How to roll a cube on it's edges on Unity 3D


I want to move a cube by making it roll on it's edges. The cube will be standing on a x-z grid and each movement it takes will make it stand on a different square of the grid.

The player will controll the movement and will only be able to make the cube roll on one direction at a time (left, right, forward or back), but the cube must always stand exactly on top of one of the grid's squares.

I don't think applying a force to the cube will help cause it could move it a little bit too much or too little. I want to achieve something like this: https://www.youtube.com/watch?v=yaAIUYuNi84 but only on the x-z plane. Notice how on each corner the cube can stop and change direction with ease, because it never moves too much or too little.

Any ideas on how to approach this?


Solution

  • If you are new to the Unity it will be useless to trowing you a bunch of codes so i am telling you the way of doing it so you can implement your own codes.

    You can create 4 empty game object which will always follow the cube on the floor and when you want to roll the cube you will rotate the cube around the empty objects.

    You can find the codes for following the cube and rotating the cube on youtube, and for the starters searching is allways good.

    So i hope you can manage it out, if you cant please write me again where did you stuck and i will be happy to answer you :)