- Home /
SphereCast inaccurate?
I am testing collision of spheres on a flat surface, like in a snooker environment.
I found that using Physics.SphereCast may not be entirely accurate when I aim a ball towards the edge of another ball. With the same source position and direction, SphereCast shows no collision, but displaying a LineRenderer using source and direction shows that an obvious collision should take place. Even applying a force on a ball from source point in the direction of the SphereCast would see a collision eventually. All done on same project settings.
So the question is... is there anything to tweak the precision of SphereCast? Thanks in advance.
Here's sample code. estimateHit is the center position of the sphere on collision. It works 99% of the time, just inaccurate when it barely hits the edge of another ball.
if (Physics.SphereCast(source, ballRadius, direction, out hit, maxDistance)){
Vector3 estimateHit = source + hit.distance*direction;
lineRenderer.SetWidth(ballRadius*2,ballRadius*2);
lineRenderer.SetPosition(0,source);
lineRenderer.SetPosition(0,estimateHit);
}
Your answer
Follow this Question
Related Questions
Polygon Collider 2D Not Precise Enough 0 Answers
Trigger Colission not only works sometimes 1 Answer
C# SphereCast isn't Inaccurate 1 Answer