- Home /
How to roll a cube
Hi everybody,
I am working on very simple project but i am stuck at what it seems very simple problem. What i need is to roll a cube like in this game:
https://www.youtube.com/watch?v=aml5FoyyKLo
Can somebody help?
Thanks
In almost any non physics based (no free movement, only a limited amount of "states"), grid based game i'd say the basis of the game is a 2D or 1D array where each index in the array corresponds to a coordinate/square on the game area.
It can for example be an int[] array where each value you assign to the array describes what is in that cell on the game area: the block you're rolling, the "level goal square", empty space or a slab onto which you can roll your cube.
Then make a class for the cube. The cube class must know it's orientation on the board and it must know which square(s) it will occupy after it makes the rotation based on your input.
With those 2, you could already have a playable prototype. Just set up a Quad to represent each square on the game area and change their colors based on their status (block/no block/empty/goal).
After you get the logic working, you can start to think about animating the block.
P.S. I know this has nothing to do with the question itself, but in this answer i wrote a working example of the type of grid system I'm suggesting. LIN$$anonymous$$
I just answered a question that has code for rolling a cube. It may be a start on what you are looking for:
http://answers.unity3d.com/questions/710087/tipping-a-cube-over.html#answer-710471
Your answer
Follow this Question
Related Questions
Advice for Intersecting Colliders 0 Answers
Unity Script causing crash 1 Answer
Rigidbody2D won't stop moving. 2 Answers
Addforce - bug with jump 2 Answers
controlling the center of mass for a car 2 Answers