Download

Rubik's cube chess game. Having trouble wrapping my head around how to make it work.

So i’m just getting back into UE4 after about 2 years of not using it. so im VERY rusty and my knowledge of the engine is pretty much shot right now.
I’m trying to make a game where you play chess on the surfaces of a rubik’s cube. on your turn you can choose to either move a piece or turn a section of the cube. besides that it plays exactly like chess.

right now I have a cube BP class that has a cube static mesh. this represents one block on the rubik’s cube. Next I have a Rubik’s Cube Class that spawns these cubes in a position that would create a much larger cube of cubes (classic rubik’s cube shape) and stores them in an array as demonstrated below.83b03ee2cabad27addf63d330dd69edfea133df9.png

Here is where I get stuck and do not no how to proceed.

How can I rotate each row or column around a central axis similar to a rubik’s cube?
Each of the surfaces of each individual cube is space a game piece can move to. I will need to manipulate each individual surface to edit its material or get info if that space is occupied or not or determine connecting spaces. Would the best way to do that is create a space BP and spawn some with cube?
I want to be able to drag the mouse and the entire rubik’s cube rotate in the direction of the mouse so that the player can get a good view of the play field. I cant seem to make this work. any ideas?

Any help would be very appreciated!

EDIT #1:

I have made a ton of progress thanks to your guidance Everynone. I’m not going to say that I understand everything that you demonstrated to its full extent but i think i have a pretty good grasp on things.

I tried to follow your work as much as I could. I had to make a few changes here and there to fit with my project. I ran into a couple of bugs that i had to solve which is what has taken me so long to respond back to this thread. I wanted to try and solve the bugs myself before coming and asking for help.

So for the Results…

The following is my spawn cube function
[ATTACH=JSON]{“data-align”:“none”,“data-size”:“icon”,“data-tempid”:“temp_116169_1504565388323_217”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

And the next figures are my Cube Clicked:
[ATTACH=JSON]{“data-align”:“none”,“data-size”:“icon”,“data-tempid”:“temp_116170_1504565533748_182”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

LETS SEE IT IN ACTION!

https://i.gyazo.com/41c64a2969711175…6b7aabbd9a.mp4

As you see it turned out really good! even if it took me a couple of days to iron out all of the bugs. the best part about it is that i actually learned a lot from your example. it enlightened me on things i was confused about and introduced me to methods i didn’t know existed! I am very grateful for your help!

My next step in the project to allow the player to rotate the cube any direction to get better views of the cube. ill definitely update everyone on my progress as I go or if i have any further questions!

Once again! THANK YOU!

**EDIT #2: **

So I have made a lot of progress so far with this, but unfortunately I think I have run into something else i cant quite wrap my head around yet.

right now I am working on the pawns that you will move around the play area. the following is my temporary pawn Mr: Mustache:

As you can see below him is a collision box. I use this to get the overlapping cube that is underneath the pawn and attach the pawn to the cube so that when i rotate a selection of the cube it also rotates the pawn. so here is the results! https://i.gyazo.com/0d93cdbaaf1dee5d…38ca8c710b.gif

So thats looking pretty good. but the issue lies in if I start to customize the cube as demonstrated in the following gif: https://i.gyazo.com/542f96d48b1bc130…ee477a2a7e.gif

Obviously as shown in the gif I don’t want the pawn to be inside a cube after a rotation. I need the rotation of the selection to push the pawn around until the rotation stops and then the pawn will attach itself to the appropriate cube. I have yet to be successful making this happen.

So question 1 is How do i make the pawn rotate around with the selection if it collides with a cube in the selection.

My second question is about moving the pawn. i’ve done some research on tile based movement. but I cant make any examples fit my project. all other projects only take into account a 2d array of tiles which usually means only tiles on an X axis. but with my project i have tiles on the X, Y, Z A, B,C, D, etc axis’.
Not to mention that its entirely dynamic. each tile could change neighbors with any rotation of the cube.
My feeble mind cannot begin to comprehend how to begin making this work.

So to reiterate,

Question 1: How do i make the pawn rotate around with the selection if it collides with a cube in the selection.
Question 2: How do i handle the Dynamic 3 Dimensional Tile Based movement around this God forsaken cube?

Paging Everynone for his unlimited knowledge. you seem to know your way around a cube.

I’ve coded one long time ago; but then came the info this “rubik” cube is patent protected and copyrighted toy, so the blueprint was removed from the project.

Do you remember how you did it?
i would love to see it if you still have the file.

right now i’m working on rotation of the rubik’s actor. the actors rotation is not affecting the array of cube objects. they do not spin with its owner. an suggestions

Here’s my take on this:

I have an object with a collision box (the thin black wireframe box) and I spawn a bunch of cubes.

By clicking on any of the cubes, I move the collider on one axis only and change its shape so it envelops a slice of the big cube. You can extend the collider to include more than a single slice since that would be how an ordinary cube works.

In this case, a slice would be 25 small cubes on an axis. (you can remove the ones inside, of course, since they’re not really used). I then add overlapping actors (small cubes) to an array.

I use *ctrl *or *shift + click *to choose a 25-slice:

The cubes that collided with the collider are attached to it. A timeline will then add 90 deg rotation to the collider which, in turn, will rotate all the attached cubes around its own axis. Once the timeline finishes playing, the cubes are detached. The CE_CubeClicked is called by a component onClicked inside the small cubes and fetches its own location.

(open in a new tab for full res)

The end result:

https://i.gyazo.com/8c61e5c58468d3c4…e41327f912.mp4

That was a cool exercise. Let me know if anything is unclear.

Whoa! you really went above and beyond for me man! Thank you so much!!! I think i understand what you are doing. Ill need to try to replicate it before ill be able to answer that for sure. ill get to work right now and provide updates on my progress. Ill bring back questions if i do not understand something. Stay tuned!

I have made a ton of progress thanks to your guidance @Everynone. I’m not going to say that I understand everything that you demonstrated to its full extent but i think i have a pretty good grasp on things.

I tried to follow your work as much as I could. I had to make a few changes here and there to fit with my project. I ran into a couple of bugs that i had to solve which is what has taken me so long to respond back to this thread. I wanted to try and solve the bugs myself before coming and asking for help.

So for the Results…

The following is my spawn cube function
[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_116169_1504565388323_217”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

And the next figures are my Cube Clicked:
[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_116170_1504565533748_182”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

LETS SEE IT IN ACTION!

As you see it turned out really good! even if it took me a couple of days to iron out all of the bugs. the best part about it is that i actually learned a lot from your example. it enlightened me on things i was confused about and introduced me to methods i didn’t know existed! I am very grateful for your help!

My next step in the project to allow the player to rotate the cube any direction to get better views of the cube. ill definitely update everyone on my progress as I go or if i have any further questions!

Once again! THANK YOU!

Looks slick. I’m curious what you’re going to do with it. It should be fairly easy to scale the whole thing up and customise the faces. I can see it ending up as a neat and potentially mind-bending puzzle. Whether it’s a game of chess or an advanced match x elements game. Or even a strategy with offensive / defensive / support units sliding into place and changing the state of game board quite dramatically.

Its funny you mention that. I’ve actually expanded my idea from the general “Chess on a cube” to something more complex. One thing ive been thinking about is how each chess pieces moves so perfectly on a chess board, but it might not translate well on to a different game surface. Of course I wont know for sure until i actually play my own game! I think i will end up having to learn my own game and find out what works and what does not. Once i have done that i can tailor the game pieces toward my game instead of just ripping them off of chess.

I’ve also been thinking about how all it takes is removing a few individual cubes from my larger cube and i have created a completely different game board with its own strategies. Which is exciting to think about the possibilities of variety!

So I have made a lot of progress so far with this, but unfortunately I think I have run into something else i cant quite wrap my head around yet.

right now I am working on the pawns that you will move around the play area. the following is my temporary pawn Mr. Mustache:

pawn.jpg

As you can see below him is a collision box. I use this to get the overlapping cube that is underneath the pawn and attach the pawn to the cube so that when i rotate a selection of the cube it also rotates the pawn. so here is the results! https://i.gyazo.com/0d93cdbaaf1dee5d…38ca8c710b.gif

So thats looking pretty good. but the issue lies in if I start to customize the cube as demonstrated in the following gif: https://i.gyazo.com/542f96d48b1bc130…ee477a2a7e.gif

Obviously as shown in the gif I don’t want the pawn to be inside a cube after a rotation. I need the rotation of the selection to push the pawn around until the rotation stops and then the pawn will attach itself to the appropriate cube. I have yet to be successful making this happen.

So question 1 is How do i make the pawn rotate around with the selection if it collides with a cube in the selection.

My second question is about moving the pawn. i’ve done some research on tile based movement. but I cant make any examples fit my project. all other projects only take into account a 2d array of tiles which usually means only tiles on an X axis. but with my project i have tiles on the X, Y, Z A, B,C, D, etc axis’.
Not to mention that its entirely dynamic. each tile could change neighbors with any rotation of the cube.
My feeble mind cannot begin to comprehend how to begin making this work.

So to reiterate,

Question 1: How do i make the pawn rotate around with the selection if it collides with a cube in the selection.
Question 2: How do i handle the Dynamic 3 Dimensional Tile Based movement around this God forsaken cube?

Paging Everynone for his unlimited knowledge. you seem to know your way around a cube.

q1: treat Mr. Mustache as a generic cube. When you attach the cubes to the (cube)collider, also attach that pawn, making it a part of the slice. Then detach after the animation.

q2: what are the allowed moves? Do you want to move around on a single surface? Hop from one surface to a neighbouring one? Move all the way around as if was a globe? Is it one tile at a time, straight line, L-shape? A zig-zag, teleport, random? All above? :smiley: If I’m not careful, can I fall into the nothingness below?

And most importantly, can he shave?

edit: I like how removing a couple of cubes from a single slice makes the whole thing an order of magnitude more complicated all of a sudden. On the other hand, this is coming from someone who has never held a Rubik’s cube…

**Q1: **I have already tried your suggestion for Q1. The first time i tried this method It worked pretty well but unfortunately there were some issues. Although, last time I did not have the box collision below the pawn. so this time when i tried this method the box collision caused it to attach for both the aligned selection and the beneath selection depending on what was selected which worked very well!! here is it in action!

But i do see a small issue that i will demonstrate in the following gif

as you see the pawn rotates with the selection when there are no cubes touching it. this looks a bit awkward and and is not the desired result. this is not the desired result. the desired result is what is demonstrated in the following gif.

I need the pawn to stay in its place when it does not interact with the a cube in the selection. but obviously you will end up with cases like the following figure:

g.png
the cube on the back end of the arrow will definitely overlap the pawn. so i need the pawn to rotate with the selection to the appropriate space when this overlap occurs.

Any ideas?

Q2: There will be multiple classes of pawns. some may be able to move differently than others, but all will follow the same rules. Currently i think a pawn has a ‘SPEED’’ which means how many spaces it can move. so a pawn with a speed of 3 can move a distance of 1 space 3 times (aka 3 moves). the following figure shows what typical movement should look like for a single move.

a.png
the black space represents the current space the pawn is occupying. Each green space represents a tile eligible to be moved to. so a pawn may change orientation to the wall,drop on the wall face below or move at his current orientation.

as far as the mustache goes. unfortunately the mustache is extremely important to the structural integrity of the entire project. I would give the player the option to remove the temporary pawns powerstache if it wouldn’t cause the game to crash. /s

I hope this helps better explain what I am trying to achieve. Thanks again for all your help!

For this, you could do a trace in the direction opposite to where the rotation is coming from. If the Pawn’s trace hits anything closer than 2x cube size, it’s going to overlap. If it’s further away, it should be fine. This should cover all of it, I guess.`

Untitled.png

When it comes to movement, I’m not sure. The most generic and modular approach would be the best as it’s all in motion. Since every cube is an actor, you could give them a bunch of flags that help you move around. CanBeSteppedOn, IsAtEdge, HasExtraFacialHair, IsMadeOfLava. When you try to move, trace ahead see what you hit, decide how to act base on the data. This should allow you to implement several different behaviours for different classes. Maybe.

Patent is gone since 2019