In my 2D billiards game, I have it so that when the user clicks and drags with their mouse, a Physics2D.CircleCast is projected from the cueball to wherever the mouse is. If the circle happens to hit the red ball, a line is rendered from the red ball's position to the direction of the normal of the collision. So it's supposed to predict where the red ball will go when it gets hit by the cueball.
If you look at the first gif below, you'll see that it works if the red ball gets hit at its center (or close to it). The red ball ends up moving more or less along the predicted line.
However, if you look at this second gif, you'll see that if the red ball gets hit closer to its edge, the predicted line is much less accurate.
Why is this and how can I fix it?
This is the prediction code I use:
if (Input.GetMouseButton(0) && cueBall)
{
Vector2 mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
var direction = (mousePos - (Vector2)cueBall.position).normalized;
var hit = Physics2D.CircleCast(cueBall.position, _radius, direction, Mathf.Infinity);
if (hit)
{
_lineMain.Draw(cueBall.position, hit.point);
_ghostBall.SetPosition(hit.point - (direction * _radius));
_lineTarget.Draw(hit.point, hit.point - hit.normal); //This is the predicted trajectory.
}
}