# Tilt maze Game Problems

Hey there everyone . am fairly new to the unity community so i will try to keep this very simple .

i am starting to work on this game ( tilt maze ) . for mobile devices Android to exact . I have good understanding of scripting and so far i have been able to get the maze to rotate using the device accelerometers using this code

``````function Update(){

var speed : float = 1.0f;
var upDown = -Input.acceleration.y * Time.deltaTime * speed;
var leftRight = Input.acceleration.x * Time.deltaTime * speed;

if(transform.localEulerAngles.x < 25 ){
transform.Rotate(upDown, 0, 0);
} else if (transform.localEulerAngles.x > 335){
transform.Rotate(upDown, 0, 0);
}

if(transform.localEulerAngles.z < 25 ){
transform.Rotate(0,0, leftRight);
} else if (transform.localEulerAngles.z > 335){
transform.Rotate(0, 0, leftRight);
}

if(transform.localEulerAngles.z >= 25  transform.localEulerAngles.z < 335){
if(transform.localEulerAngles.z < 180){
transform.localEulerAngles.z = 24.9;
} else{
transform.localEulerAngles.z  = 335.1;
}
}

if(transform.localEulerAngles.x >= 25  transform.localEulerAngles.x < 335){
if(transform.localEulerAngles.x < 180){
transform.localEulerAngles.x = 24.9;
} else{
transform.localEulerAngles.x  = 335.1;
}
}

if(transform.localEulerAngles.y != 0){
transform.localEulerAngles.y = 0;
}

}
``````

I have this code attached to the maze while having a marble on the plane(Maze) it self using the plane rotation to apply gravity on marble .
the marble have a rigid body attached to it with mass of 0.1 the plane have mesh collider attached to it .
i have the maze , camera , lights , attached to as child to empty game object.

there are some problems that i am facing now .
1- the recovery time from being at 20 degrees on z axes to -20 degrees affects the marble causing some sort of delay in the movement
2- the rotation it self is not that smooth ( sometimes it act funny )
3- the maze will tilt ok if i go slow/moderate on the rotation of the device but if i turned it too hard the maze will go through the ball

any ideas about the ball/maze physics setup and on controlling the tilt would be appreciated . Am also going to release the whole project once it is done

When dealing with physics like that, it’s probably a good idea to not rotate the entire maze, as it can cause plenty of collision issues, especially with fast movement.

If you don’t want to be able to quickly tilt to make the ball jump or anything, I recommend not tilting the entire maze, but tilting the camera and change the gravity direction of the ball, based on the rotation of the device, which should give the same effect, without all the collision issues.

yes i have read that somewhere else with no idea of the exact implementation. By changing the gravity of the ball do you mean Physics.gravity ?

i am trying to get the feel that the maze is not moving and am pretty sure tilting the camera will show that the maze is moving if am getting what you say correctly

I was assuming you wanted the actual maze to look tilted as well!
If not, just modify the gravity of the ball based on device rotation.

If you don’t have any other rigidbodies, you can modify Physics.gravity.

If you do have multiple rigidbodies, just have a constant force vector in the ball’s FixedUpdate() loop