Page 1 of 1
Several interlocking staticmeshes?
Posted: Thu Mar 14, 2013 1:50 am
by chebob69
In my game I have a terrain, the physics being handled by a staticmesh. I want to achieve particle effects that depend on the type of ground the character is walking over (grass/sand/dirt). I'm guessing the best way to do this is to have different physics objects for each type and doing a raycast?
How well does Bepu cope with a character controller constantly moving between different staticmeshes? Would it work out more efficient to have 1 staticmesh to handle the characters collisions and then 3 smaller ones overlaying the main one that don't interact with the character, just for raycasting?
Thanks
Re: Several interlocking staticmeshes?
Posted: Thu Mar 14, 2013 5:45 am
by Norbo
How well does Bepu cope with a character controller constantly moving between different staticmeshes?
It would work fine in terms of behavior. Pushing a box across a triangle edge is more likely to hit a 'bump' when crossing between two separate meshes, but the character usually doesn't feel such bumps when walking around due to its shape.
I'm guessing the best way to do this is to have different physics objects for each type and doing a raycast? Would it work out more efficient to have 1 staticmesh to handle the characters collisions and then 3 smaller ones overlaying the main one that don't interact with the character, just for raycasting?
Performance wise, it's better if there's only one whole mesh being tested for collisions.
While using separate meshes for raycasting is an option, you could also use StaticMesh.Mesh.Tree.GetOverlaps with a ray, or just a bounding box, to find nearby triangles. The indices returned can be used to look up particular triangles in the mesh. Once you know what triangle the character is near, you can look up the material or whatever other information you want in supplementary structures.
Note that this query returns all triangles whose bounding boxes intersect the query shape. So, if a ray is used, it isn't guaranteed that a returned triangle actually is hit by the ray, just that the ray came near. This is the same function used by StaticMesh.Mesh.RayCast to collect triangle candidates- you can check that function for an example of using Toolbox.FindRayTriangleIntersection to narrow down the candidates to only those triangles which were truly intersected.
Re: Several interlocking staticmeshes?
Posted: Fri Mar 15, 2013 6:57 am
by chebob69
Thanks Norbo, nice clear answer as always.
Ok, well the StaticMesh.Mesh.Tree.GetOverlaps function seems to do the trick nicely. I've got it working so that it prints out the index of the first triangle found
by a raycast. Is there a particularly good way of determining these triangles indices outside of runtime? I obviously need to group them into 3 or 4 different ground
types. I guess it would be possible to manoever the character controller around each of the ground types and append the indices to a few lists, but that sounds a bit
annoying. Anything else you could recommend?
Re: Several interlocking staticmeshes?
Posted: Fri Mar 15, 2013 4:41 pm
by Norbo
If the imported content has the materials associated with each triangle stored in some way, you could extract that data during content processing and store it for runtime use. That would allow an artist to 'paint' the materials directly in their tools in a nice WYSIWYG manner.