Hi all,
I’m currently making a simple tiltable ball and maze game. My ball and maze are both FBXs imported from 3DS Max. I have the ball set up with a rigidbody and a sphere collider, and the maze is a mesh collider. Upon preview, the ball sits in the maze - i.e. it doesn’t fall through it. But when I tilt the maze, it passes straight through the floor. I have read that there’s a problem with this with small meshes, but i intentionally made my maze object quite large (160x160 generic 3DS units) to be on the safe side.
I’m not sure if it’s an error in the setup, or the code.
Here’s my (rather inefficient, i admit) code:
#pragma strict
var rotationAmount = 1;
var xClamp = 30f;
var yClamp = 30f;
function Update()
{
//rotating the maze
if(transform.localEulerAngles.x < xClamp ){
transform.Rotate (Input.GetAxis("Vertical") * -rotationAmount, 0, 0);
} else if (transform.localEulerAngles.x > (360-xClamp)){
transform.Rotate (Input.GetAxis("Vertical") * -rotationAmount, 0, 0);
}
if(transform.localEulerAngles.z < yClamp ){
transform.Rotate (0, 0, Input.GetAxis("Horizontal") * rotationAmount);
} else if (transform.localEulerAngles.z > (360-yClamp)){
transform.Rotate (0, 0, Input.GetAxis("Horizontal") * rotationAmount);
}
//clamp rotation
if(transform.localEulerAngles.z >= yClamp && transform.localEulerAngles.z < (360-yClamp)){
if(transform.localEulerAngles.z < 180){
transform.localEulerAngles.z = (yClamp-0.01);
} else{
transform.localEulerAngles.z = ((360-yClamp)+0.01);
}
}
if(transform.localEulerAngles.x >= xClamp && transform.localEulerAngles.x < (360-xClamp)){
if(transform.localEulerAngles.x < 180){
transform.localEulerAngles.x = (xClamp-0.01);
} else{
transform.localEulerAngles.x = ((360-xClamp)+0.01);
}
}
if(transform.localEulerAngles.y != 0){
transform.localEulerAngles.y = 0;
}
//debug code - detect if nothing is pressed
if ((Input.GetAxis("Vertical") == 0) && (Input.GetAxis("Horizontal") == 0)){
Debug.Log("Nothing is pressed.");
}
}
function OnGUI ()
{
var xRotation = Mathf.Round(transform.localEulerAngles.x * 10) / 10;
var zRotation = Mathf.Round(transform.localEulerAngles.z * 10) / 10;
GUI.Box(Rect(10,10,200,130),"X Rotation:"+xRotation+"
Z Rotation:"+zRotation);
}
Any ideas would be most welcome!