Hi,
Firstly; I am new to game development, and DOTS/Physics, so I’m not sure if I’m even taking the right approach here, but I would appreciate any help anyone can give.
I’m attempting to procedurally generate a 3D world which consists of hexagons wrapped into a cylinder. I’ve tried a few different approaches, but at the moment I’m doing it by generating a unique mesh for each hexagon cell, with the vertices at world positions, and 0 translation. Note, I did try the same with a ‘single’ mesh and translating/rotating each one correctly, but it gave me small render bugs where each hex met.
Anyway; that’s working, and now I’m attempting to raycast to touch each hex. I have created a mesh collider for each mesh, then do a Unity.Physics collision world CastRay to find the hit entity.
It does work - but is inaccurate. I’ve verified the ray direction/length is correct (with Debug.DrawRay), so I suspect the collider mesh might be out of sync with the real mesh?
If that image doesn’t work, link: unity raycast wrong - Album on Imgur
Here’s the creation of the mesh collider (vertices, triangles are the verts/indices from each mesh created):
using (var positions = new NativeArray<float3>(vertices, Allocator.Temp)) {
using (var indices = new NativeArray<int>(triangles, Allocator.Temp)) {
var collider = Unity.Physics.MeshCollider.Create(positions, indices);
entityManager.SetComponentData(cell, new PhysicsCollider {
Value = collider
});
}
}
So; a couple of questions:
What could be causing this?
Is this even a remotely sane idea? I would like to be able to support a large map size; so there maybe hundreds of thousands of these meshes in the game - will this just be too much even with ECS/DOTS?
I’m using a mesh collider as I don’t think any of the built in colliders would work with hexagons (for detecting when the mouse is over that hex/click etc) - but am I wrong here? Could a sphere approximate it, and be a lot faster?