Rubik's Cube with UE Blueprints

Each block Blueprint is placed at 0,0,0 and its components are adjusted to an offset location.


The function above highlights any block that the cursor hovers over. The Highlight effect is driven by switching the emissive on and off.


On each frame a line is traced from the cursor to the blocks to determine the point of impact (OnClick and OnRelease) and the impact normal direction of the highlighted cube (to determine which side of the block is being press).


When a block is clicked, it sets a vector of the impact location and then sets a vector for the location where the block was released. Next, it compares each axis of the “OnClick Impact location” with the “OnReleased Impact Location” to determine if the player is dragging in a positive or negative direction.


(Inside the "Rotate Blocks" Function) First the function determines which side of the cube is being impacted. Next, it creates a volume based on which axis the cursor is being dragged along. Then it gets the "DragDistance" boolean to set the desired rotation direction to negative or positive. Finally, the function grabs all of the cubes with in the set volume and rotates them around the set axis. 

The function above subtracts the Y-Axis of the "Impact End Location" from the Y-Axis of the "Impact location" and also subtracts the Z-Axis of the "Impact End Location" from the Z-Axis of the "Impact location." This causes the blocks to rotate around the axis with the higher drag distance.

Download the Sample Rubik's Cube Here:

Rubik's Cube Download Link