- Edited
Hi, I am making a 3D Rubik's cube simulation/game. Currently, you're able to rotate the green/red faces using the left/right arrows, and the orange/blue faces using the up/down arrows. This utilises the updated Tweens to animate the sides as they rotate.
There is an issue however, and it isn't consistent either. Basically, if you rotate one of the z-axis sides (green or blue) and proceed to rotate a y axis side (red/orange), everything is completely fine and the pieces rotate without hassle. However, if you have the x-axis sides on any rotate other than 0°x and proceed to rotate the z-axis sides, the pieces merge and do not rotate in the correct ways.
For instance, if I rotate the red side to -90°X and then rotate the green side to -90°Z, instead of moving in a clockwise-fashion the pieces that were "from the red side" move in a clockwise fashion along the Y AXIS. Please, I do not understand how it works one way but not the other and it's hurting my brain a bit.
TEST 1:
Initial turn of the green side, the negative Z axis, everything is smooth and works as expected
Next to turn is the negative x, or red side, and again everything is smooth and works as expected
As expected, the negative x axis poses no problems
However, after turning the negative Z axis after turning the negative x axis just once, the rotations become messed up and merge some pieces (not literally)
Turn 2 of the negative z axis
Turn 3 of the negative Z axis. You can see how it isn't any better.
I have tested it with +Z/-X, +Z/+X, -Z /+X, and -Z/-X. All four instances caused them to "merge", and all four instances required the X rotation be on anything above/below 0°X.
If anyone knows a plugin to fix this, or if there even is a single fix, please let me know otherwise my simulation might not work like this. Thanks in advance to any helpers
' Script:
extends Node3D
@onready var pi1 = $Piece1
@onready var pi2 = $Piece2
@onready var pi3 = $Piece3
@onready var pi4 = $Piece4
@onready var pi5 = $Piece5
@onready var pi6 = $Piece6
@onready var pi7 = $Piece7
@onready var pi8 = $Piece8
var solved = true
var tween
var red_face
var green_face
var orange_face
var blue_face
var yellow_face
var white_face
# Called when the node enters the scene tree for the first time.
func _ready():
solved = true
if solved == true:
pass
func _process(delta):
if Input.is_action_just_released("ui_right"):
rotate_red_cw()
elif Input.is_action_just_released("ui_left"):
rotate_green_cw()
elif Input.is_action_just_released("ui_up"):
rotate_orange_cw()
elif Input.is_action_just_released("ui_down"):
rotate_blue_cw()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func rotate_red_cw():
if tween and tween.is_running():
return
red_face = [
pi1,
pi2,
pi3,
pi4,
]
tween = get_tree().create_tween().bind_node(self).set_parallel().set_trans(Tween.TRANS_CUBIC)
for CharacterBody3D in red_face:
tween.tween_property(CharacterBody3D, "rotation_degrees", Vector3(CharacterBody3D.rotation_degrees.x-90, CharacterBody3D.rotation_degrees.y+0, CharacterBody3D.rotation_degrees.z+0), 0.5)
tween.play()
tween.is_running()
var tmp = pi1
pi1 = pi3
pi3 = pi4
pi4 = pi2
pi2 = tmp
func rotate_green_cw():
if tween and tween.is_running():
return
green_face = [
pi1,
pi3,
pi6,
pi8,
]
tween = get_tree().create_tween().bind_node(self).set_parallel().set_trans(Tween.TRANS_CUBIC)
for CharacterBody3D in green_face:
tween.tween_property(CharacterBody3D, "rotation_degrees", Vector3(CharacterBody3D.rotation_degrees.x+0, CharacterBody3D.rotation_degrees.y+0, CharacterBody3D.rotation_degrees.z-90), 0.5)
tween.play()
tween.is_running()
var tmp = pi6
pi6 = pi8
pi8 = pi3
pi3 = pi1
pi1 = tmp
func rotate_orange_cw():
if tween and tween.is_running():
return
orange_face = [
pi5,
pi6,
pi7,
pi8,
]
tween = get_tree().create_tween().bind_node(self).set_parallel().set_trans(Tween.TRANS_CUBIC)
for CharacterBody3D in orange_face:
tween.tween_property(CharacterBody3D, "rotation_degrees", Vector3(CharacterBody3D.rotation_degrees.x+90, CharacterBody3D.rotation_degrees.y+0, CharacterBody3D.rotation_degrees.z+0), 0.5)
tween.play()
tween.is_running()
var tmp = pi5
pi5 = pi7
pi7 = pi8
pi8 = pi6
pi6 = tmp
func rotate_blue_cw():
if tween and tween.is_running():
return
blue_face = [
pi2,
pi4,
pi5,
pi7,
]
tween = get_tree().create_tween().bind_node(self).set_parallel().set_trans(Tween.TRANS_CUBIC)
for CharacterBody3D in blue_face:
tween.tween_property(CharacterBody3D, "rotation_degrees", Vector3(CharacterBody3D.rotation_degrees.x+0, CharacterBody3D.rotation_degrees.y+0, CharacterBody3D.rotation_degrees.z+90), 0.5)
tween.play()
tween.is_running()
var tmp = pi2
pi2 = pi4
pi4 = pi7
pi7 = pi5
pi5 = tmp'