- Home /
Rubik's Cube problem
All I basically want to achieve right now is to see how this http://www.onlinegames.net/games/807/rubiks-cube.html is get done.
How could it be done. I'd want to spice it up later, and basically learn from the inner workings of such a code.
All I got so far though is
var currentMouseX = 0; var currentMouseY= 0; var rotationSpeed = 100; function Update () { currentMouseX= Input.mousePosition.x; currentMouseY= Input.mousePosition.y; checkWhichWayDidTheMouseGo();
actuallyRotate();
}
function actuallyRotate(){ transform.Rotate(RotationAxis Time.deltaTime rotationSpeed); }
var mouseXOnClickPosition= 0; var mouseYOnClickPosition= 0; var mouseDifference = 50; var enableMeasuringDistance= true;
function checkWhichWayDidTheMouseGo(){ if(Input.GetMouseButtonDown(0)){ mouseXOnClickPosition = Input.mousePosition.x; mouseYOnClickPosition = Input.mousePosition.y;
enableMeasuringDistance = true;
}
if(Input.GetMouseButton(0) && enableMeasuringDistance){
if(mouseDifference <= mouseXOnClickPosition - Input.mousePosition.x ){
print("left");
RotationAxis=Vector3.up;
enableMeasuringDistance = false;
}
if( mouseDifference<= Input.mousePosition.x - mouseXOnClickPosition ){
print("right");
RotationAxis = -Vector3.up;
enableMeasuringDistance = false;
}
if(mouseDifference <= mouseYOnClickPosition - Input.mousePosition.y){
print("down");
RotationAxis = -Vector3.right;
enableMeasuringDistance = false;
}
if( mouseDifference<= Input.mousePosition.y - mouseYOnClickPosition ){
print("up");
RotationAxis = Vector3.right;
enableMeasuringDistance = false;
}
if(Input.GetMouseButtonUp(0)){
enableMeasuringDistance = false;
}
}
}
and it doesn't do what it should... I made a checker to see if mouse was moved left or right (on the screen) and make a cube(so far one cube, not divided into 3x3;|)rotate the same way, but the rotate is constant, and if it gets upside down, it doesn't really rotate relative to camera... basically this thing doesn't work.
Can somebody teach us how to do such a cube? example: http://www.onlinegames.net/games/807/rubiks-cube.html
That would be much appreciated. Thank you.
Could you tell me, how can i make the same? or could you shared your code source?
;)
Your answer
Follow this Question
Related Questions
How to have objects with multiple parents capable of seperate rotation 3 Answers
Get the rotation vector from 2 vectors 1 Answer
trying to make the inside of a rubik's cube 2 Answers
Get the rotation matrix if you have the start and end position 1 Answer
change variables in another object's script's instance 1 Answer