Raycast against cone uses margin, other primitives do not
Posted: Tue Aug 23, 2016 9:08 pm
Hello, it's me again!
I've encountered another relatively minor issue. I noticed that all raycasts against a Cone seem to hit above its surface, while for all the other primitives its hits right at the surface.
When I went through the code, I noticed that ConeShape is the only one which doesn't have its RayTest method overridden and instead uses the generic method in MPRToolBox instead, which seems to take into account the margin.
I found that a quick (and dirty?) way to remove the inconsistency is to override the RayTest method, only to set the collisionMargin to zero before running the MPRToolBox method and returning it to original afterwards, like so:
Could this cause some significant problems? How does this compare to writing a dedicated method for a cone as the other primitives have? (I suspect it has suboptimal performance, but other than that I don't know)
I've encountered another relatively minor issue. I noticed that all raycasts against a Cone seem to hit above its surface, while for all the other primitives its hits right at the surface.
When I went through the code, I noticed that ConeShape is the only one which doesn't have its RayTest method overridden and instead uses the generic method in MPRToolBox instead, which seems to take into account the margin.
I found that a quick (and dirty?) way to remove the inconsistency is to override the RayTest method, only to set the collisionMargin to zero before running the MPRToolBox method and returning it to original afterwards, like so:
Code: Select all
public override bool RayTest(ref Ray ray, ref RigidTransform transform, float maximumLength, out RayHit hit)
{
var _tempMargin = collisionMargin;
collisionMargin = 0f;
var result = base.RayTest(ref ray, ref transform, maximumLength, out hit);
collisionMargin = _tempMargin;
return result;
}