Cube flip kinda

Heya, Sorry about the title, I just don’t have a clue want this would be called…

Is there a tut on how to make your cube do this? I have a level but now been trying to do the cube flip or is it amis?

You can use transform’s rotate function and choose which axis to turn on. I would suggest making a new scene or project and putting a cube in front of the camera. Then put a script on the cube and play with the different rotation functions. Once you do that what you see in the video will be a matter of syncing the rotation and some movement.

1 Like

I’d get lazy and just animate it. The actual core came mechanic would just be a dot moving between spaces on the board.

1 Like

This. No need for code in this case. Apply root motion and animate it. Actually, you could have only one animation and just rotate the cube then play the animation. That’s for the extra lazy people.

I’d actually build the rest of the game as a set of finite locations the cube can go. That way the cube is confined to the board squares. You won’t have any possibility of getting your root motion slightly out of sync and ending up not on a square. This game would be a great candidate for MVC design, the actual game could be dramatically simpler then the visuals shown.

1 Like

Is mecanim really easier to use than a little scripting?

Depends if I can convince someone else to do the animation for me :slight_smile:

The pivot is on the edge of the cube.

1 Like

create a GameObject at the edge, parent the cube to that GameObject, do the rotation to the GameObject, unparent the cube, destroy the GameObject

This is what i did for my company’s game. As it’s a dice game, its impossible to do it with preset animation

It’s totally possible with preset animation. In this case just set the rotation to zero in the very last frame of the animation.

well yes, not totally impossible
but you will have to make animation for each face of the dice,
or you parent/unparent it to an empty animated GameObject

Well like I said, that is not necessary. You can animate with one face and play the animation just once. Once you need to play the animation again, rotate the cube to face the movement direction and reset the rotation. Since it is a cube, you cannot see the rotation resetting.

The creation and destruction of the GameObject is totally a waste of resources. On top of that, you can just set the pivot to the edge like what @TylerPerry said. Then just rotate it based on that pivot point. Move as necessary. Much more efficient.

I was talking about my game, which used dices

I just want to make it shoot and forget. Of course you can reuse that empty GameObject. You can also use transform.RotateAround()

2 Likes

so animation seems like total overkill for this…
The rotation of the cube is important (think about how a dice rotates and what the new face becomes), which means you couldn’t have 1 animation and rotate it, you’d have to have 4. Then because there are 6 faces, you’d need 6 times that, 24 animations, plus a way of managing which one to use…
(Maybe you could do just 4 anims and keep it separate from the faces, I’m not sure how mecanim works)

Or, just use one line of code:

Set the point vector as the edge of the cube that is on the side you want to rotate around. Then just set up conditions for each side and there you have it.

This is one of those problems that is super simple to code and anything else makes it unnecessarily complicated.

Edit:
Oops, didn’t spot the post above suggested this solution! :slight_smile:

Animating it will make the feel easier to tweak, the cube should struggle while pushing itself up, then effortlessly fall. It only requires one animation then set the faces with code.

True, but you could just tween the angle parameter, which is just one more line of code :wink:

Either way, those are both fine and OP can choose any method he prefers. :slight_smile:

/thread

Pff, I was one of the first (first reply, in fact) to mention toying with rotation functions in a simple script.

2 Likes

Totally skimmed over that one too it seems, hah