- Home /
Question by
babaji1234 · Jun 21, 2014 at 03:28 PM ·
c#raycastraycastingmathvoxel
raycasting without colliders
I am making a voxel based game which is near completion. The main problem I have is raycasting as I have removed the mesh colliders for speed and so am using a custom solution which is incredibly inaccurate. So, if anyone has a solution please tell me and I also have the 3-dimensional array for data. Here is the code I currently use-
public static bool Raycast (Ray ray,out RaycastHit hit,float dist) {
for(float i = 0;i < dist;i+=0.5f) {
Vector3 rDir = ray.GetPoint(i);
if(isSolid(rDir)) {
hit = new RaycastHit();
hit.point = rDir;
return true;
}
}
hit = new RaycastHit();
return false;
}
static bool isSolid (Vector3 pos) {
return (worldGen.Block(pos) != Blocks.Air);
}
//WorldGen.Block
public static int Block (Vector3 pos)
{
return data[(int)(pos.x),(int)(pos.y),(int)(pos.z)];
}
Thank You.
Comment