- Home /
Question by
Flamegiraffe · Dec 28, 2016 at 08:41 AM ·
raycastmesh collidermouse positionraycastsmesh colliders
Raycast onto Mesh Collider unreliable.
I'm trying to make an RTS game for which I created the map myself as a mesh in Blender. My map is made up of separate convex parts, each equipped with a convex mesh collider. The plane under all these parts has a box collider, which reliably receives the raycasts. I have the following code for finding the clicked position on the map, which works only sometimes on the mesh colliders.
The question: How can I make the raycasts hit the mesh colliders reliably? Thank you for any help in advance.
Ray ray = mainCamera.ScreenPointToRay (Input.mousePosition);
RaycastHit[] hits;
hits = Physics.RaycastAll (ray.origin, ray.direction, clickDistance);
foreach (RaycastHit hit in hits) {
if (hit.collider.gameObject.tag == "Map") {
return hit.point;
}
}
return Vector3.zero;
Comment