cube movement

hello all,

i am very new to unity(i have started 2 days before) i want to move the cube like if press right key cube should rotate 90 at right and translate its width distance. same for all the direction (left forward and backward)

thanks in advance

Welcome to the forum!

Does the FPSWalker script (menu Component > Scripts > FPS Walker) do what you want?

thanks for quick reply.

see the scene is: i have dice(dimension 22)which has six faces marked from 1 to 6(as in snake-ladder dice).now i want to move that dice over the board(say plane). the board has dimension 10width of dice and 10*height of dice.where 10 is number of rows and colns, the board has. that means the board has square structure(like chess board).
now put the dice over the board.and move the dice so that in each move the dice show new face at upper side.
something like the below image.
how can i move the dice over the below mentioned surface.
Thanks in advance

217859--7932--$dice_246.jpg
217859--7932--$dice_246.jpg

you mean, you want to rotate the die around its edge at 90 degrees?

:smile: yes but how can i do this …
thanks

I would have a pivot (just an empty game object) that moves to the edge you want to rotate around, then make the pivot a parent of the cube, then rotate the pivot at 90 degrees.
I am not sure if this can be handled with animation. I never used animation. (still haven’t downloaded unity 2.6) but might be a better way…

here’s a quick example on the pivot method:

var pivot : Transform;
// this is half the length of the side of the cube
var halfSideLength : float = 0.5;

function Start(){
//set the pivot to be in the plane the cube is on
pivot.position.y = transform.position.y - halfSideLength;
}
function Update () {

	if (Input.GetKeyDown (KeyCode.RightArrow)){
		pivot.position.x = transform.position.x + halfSideLength;
		transform.parent = pivot;
		pivot.localEulerAngles.z = -90;
		transform.parent = null;
		pivot.rotation = Quaternion.identity;
	}

}

Thnks for quick reply…
i want to rotate the die at every edge.so should i take that number of gameobject. and one more thing
should i use animation in between?

thanks again

you would attach this script to your die. You would have only one empty game object that you assign to the pivot variable. You would add to the script the code for left, up and down.
If you would like to rotate the die ‘smoothly’ you would have to either interpolate between the final rotation and the current rotation, or increment the angle of rotation until you reach 90. Or try animation. I am sorry, but I don’t know which approach is best here.

Thanks for reply…

first tell me on which edge should i place that pivot(empty) gameobject at lower of upper edge? As i have to rotate the cube at every edges. shall i place the pivot at runtime? that means if i want to move move right then place pivot at right face edge and if i want left side move then place pivot at left? shall this work?

the movement of die is like…

pls help…
Thanks in advance

yes. you are changing the pivot position at runtime with this line. Doesn’t matter where you place it initially.

pivot.position.x = transform.position.x + halfSideLength;

you should be able to make a js script with the code I posted above, attach it to a cube, input the halfSizeLength (say 0.5 if your cube is 1x1x1) create an empty game object and assign it to the pivot. Then the right arrow should rotate your cube around the right lower edge at 90. You can do the other edges. This will not be animated though. Hopefully somebody else will tell you how to proceed here. I would personally just increment the rotation angle in the update function.

Thanks for help.
working on animation thing… :roll:

now the scene is…there are number of dies present inside the board(as shown above post)
what i want to is; attach the similar number of upper faces and destroy the connected same number dies.
now i created suppose 10 dies using prefab.but the problem is i want to rotate+translate each die independently(which ever die i select).
but if i move any one die, other dies are also moved?

what should i do to select and rotate die independently…