# Rolling a cube.....?

I have seen the rolling ball template. I am curious if there is anyplace I can look and maybe learn/figure out, how to ‘roll’ a cube. Just hit w a s d and have it roll to that direction… if that makes sense. I guess rotate would be more proper than roll.

I guess I should be even more specific… I can change the ball to a square mesh, and it will ‘roll’… what I want is not the torque movement like the ball, but rather each time key is pressed, it just rolls to it’s side. so you never have ‘diagonal’ movement. just up/down and left and right.

I haven’t had any luck with that. I can use torque like the ball… but that is based on how long you hold the key, and then it get’s to bouncing around. I used an add rotation, and that rotates as I can tell based on the colors… but it rotates in place instantly, doesn’t move. Will keep digging. Thanks.

Could you rotate the cube on the edge rather than around the center ?

Technically, the object rotates around its pivot. If that pivot is located in the object center, it will rotate around just that.
The pivot itself is fixed relative to the mesh vertices, so simply moving the pivot to an edge will not do the trick…
What you could do is: Create an animation that rotates the cube around the center. And then move it across the floor. If the cube rotation speed and the lateral movement across the floor are matched, it creates the illusion of a “rolling” cube.

PS: You also need to add a sinusoidal vertical movement with the minima when the cube bottom surface is flat with the floor plane.

So the cube would need a skeleton in order to generate animations, wouldn’t it?

I had to look up that sinusoidal bit… found this, so I think I understand what you are saying, the cube pretty much needs to slow as it approaches it’s resting place so the animation looks more natural. Is that right?

Is my tutorial the one you did?

Is that not the motion you are going for? Can you explain more clearly what you are trying to accomplish?

No, I did not even find your tutorial with all the searching I did. But it exactly what I was trying to accomplish. THANKS. Now I can go through and see how it is done and grasp how you accomplished it.

Only if you would deform the cube. But since the cube just rolls (like a dice), you dont need a skeleton. A simple rotation is enough.

@cyberreality … work and life have kept me away from the PC mostly… but I recall when I started looking at your code, there was something in there about steps… max and something else… did those have to do with the size of the cube? When I started messing with it I made the cube twice as long (a rectangle rather than a cube) and thought perhaps those were related to the size of the cube. So of course the rotation of the rectangle shape did not work right… but that’s when life kicked in.

What I meant is: Imagine the pivot being at the cube center needs to move up and down periodically.

If you just move the pivot across the floor, the bottom of the cube would “dig” into the ground…

@cybereality I’ve looked through your tutorial and it’s exactly what I am trying to achieve. I downloaded the project to better understand some of the functions and variables however I can only see the Set State function on the BP_MeterCube pawn. Are the others hidden away somewhere?

Most of the code is in the level blueprint. At the top on the editor, click Blueprints -> Open Level Blueprint. Then look in the Event Graph, and also there are like 6 functions as well that have all the code for the cube movement. Hope that helps.

Found it. Thanks @cybereality

Can you tell me how iffffff you still alive : )