# Move an object around all 6 sides of a cube

For the past couple of days I’ve been experimenting with different ways to move one smaller cube around a big cube. Each method I’ve tried seems to work but not perfectly as there are bugs or other problems with the solution. I’ll attach a few photos to show you what I’m trying to achieve. It’s a 3D snake game where the player moves around a cube.

I’ve tried three different things each with not the best results.
So to start off with I’m just using a basic movement script to move the cube around.

void playerMovement(){

player.transform.Translate (Vector3.forward * (Time.deltaTime * speed));

if (Input.GetKeyDown ("left")) {
player.transform.Rotate (0, -90, 0);
}

if (Input.GetKeyDown ("right")) {
player.transform.Rotate (0, 90, 0);
}
}

So the first thing I tried was using box colliders with triggers set on the edges to rotate the player 90 degrees. This presented two problems. The first problem being that I needed two triggers on each edge and this would make the player cube rotate inside in the bigger cube. So I added a wait timer before you could rotate again. This worked but now if the player moves around the edges and stays in contact with the cube once he exits either side it will rotate the player cube inside the bigger cube again.

IEnumerator waitForExit(){
yield return new WaitForSeconds (1.5f);
player.GetComponent<movement>().canRotate = true;
}

void OnTriggerExit(Collider other) {
if (player.GetComponent<movement>().canRotate == true) {
other.gameObject.transform.Rotate (90, 0, 0);
player.GetComponent<movement>().canRotate = false;
player.GetComponent<movement> ().disableTurn = false;
StartCoroutine (waitForExit ());
}

}

So the last thing I tried was using a downwards force on the cube that would make the cube stick to the surface no matter what side it was on. But this presented an issue where when the cube tipped over the edge it would bounce and throw off the rotation slightly. Even with a freezed rotation it would still give the same result.

void FixedUpdate(){