Hi all,
Collisions between my mesh collider and a sphere with a collider and a rigidbody seem to be very unreliable. First off, here’s a build of my project:
http://davidmulqueen.kaen.org/Unity/Builds.html
The maze is an FBX imported from 3DS Max, with a mesh collider. It’s composed of a 16x16 grid of cubes, attached to each other for the base, and extruded upwards to form the walls. The ball is a Unity sphere with a sphere collider and a rigidbody. My code is in FixedUpdate on the maze, and tilts it (yes, it’s horribly inefficient!)…
#pragma strict
var rotationAmount = 1;
var xClamp = 30f;
var yClamp = 30f;
function FixedUpdate()
{
//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);
}
I’ve reduced fixed timestep to 0.01, I’ve made my sphere collider a little smaller than the ball, and still I continue to have collision issues. Any suggestions would be very welcome!