- Home /
turning CONVEX 'on' via script
enter code here OnMouseDown(){
transform.parent = null;
rigidbody.isKinematic = false;
transform.InverseTransformPoint(transform.position);
// all above is working just as planned
//here need it so Convex is turned on the MeshCollider
//but there is an error with this \/
transform.collider.convex = true;
}
I get the error: 'convex' is not a member of 'UnityEngine.Collider' why can't I access the convex toggle this way? -thank you
Answer by ivarboms · Feb 07, 2013 at 09:45 AM
The class Collider does not have a 'convex' property, MeshCollider does. The following code does what you want:
transform.GetComponent<MeshCollider>().convex = true;
PS: You're using InverseTransformPoint incorrectly. It returns a Vector3, which you are not using, so the function call will essentially do nothing.
Thank you!!! I was running around all day trying to figure this out... Also you're right about InverseTransform, but i swear before when I didn't have it on the object would instantly move to the far corner of the map... probably had some other part of script active and messed it up.
Thank you again!
Btw, in addition this line:
transform.InverseTransformPoint(transform.position);
will return Vector3.zero because transform.position is the origin of the local coordinate system. Transferring the worldspace position into it's own local space will always result in Vector3.zero (0,0,0)
Your answer

Follow this Question
Related Questions
mesh trigger only triggers on intersection with mesh unless convex 3 Answers
2D Polygon Convex Decomposition Code 1 Answer
How to show an object convex hull? 1 Answer
How get mesh from convex mesh collider? 0 Answers
Is there ANY possible way to use a mesh collider(without convex) with a rigidbody? 1 Answer