- Home /
The question is answered, right answer was accepted
collision between a rigidbody and a mesh collider not working
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+"\nZ Rotation:"+zRotation);
}
Any ideas would be most welcome!
Answer by kaini_industries · Sep 26, 2013 at 10:31 PM
never mind, solved it. it was that the mesh and the rigidbody were in contact at startup. i moved the ball a fraction up and it's picking it up now.
Follow this Question
Related Questions
Unreliable collision detection between rigidbody and mesh collider 1 Answer
Workaround to Non-Convex mesh colliders with non-Kinematic RigidBodies? 1 Answer
How to remove internal triangle/faces when combining mesh 0 Answers
Why attach a kinematic rigidbody to a collider that moves a lot? 1 Answer
Rigidbody objects not colliding. 4 Answers