hello,
I am trying to cast a raycast onto a custom 3D model using a mesh collider.
But the problem is the raycasting only works when the mesh collider is Convex.
and i really can’t use Convex.
Is there a solution for this?
Greetings.
hello,
I am trying to cast a raycast onto a custom 3D model using a mesh collider.
But the problem is the raycasting only works when the mesh collider is Convex.
and i really can’t use Convex.
Is there a solution for this?
Greetings.
A RayCast will hit a mesh collider regardless if it is convex or not, as long as it is not set to isTrigger = true.
Anyway, if it is indeed a trigger then you have to use a compound collider (multiple convex colliders on the same gameObject).
That’s what i thought too, but somehow it really won’t hit.
This is the raycast script:
void StayOnGround ()
{
int layerMask = 1 << 8;
RaycastHit hit;
if (Physics.Raycast(transform.position, -Vector2.up, out hit, Mathf.Infinity, layerMask))
{
transform.position = new Vector3(transform.position.x, hit.point.y, transform.position.z);
}
}
And the screenshot of the scene:
http://imgur.com/1b9v1sU
I really don’t know why it won’t work.
But setting it to convex works, so that is odd.
non convex colliders are pretty expensive and not too reliable just use multple convex ones
It could be a problem with flipped normals, as well.