I’m currently making a 2D Billiards game where the cue follows the players mouse around the ball, and when the user clicks the mouse it shoots the ball. I have a linerenderer running from the ball and it stops on whatever object it collides with. That works well, but I’m struggling with the predicted trajectory line. I have one working and it roughly shows where the ball will go, but the steeper the angle (the more side-on the shot is), the less accurate it becomes! Can anyone help me with this? Thanks.
RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.up); hitPoint.position = hit.point; Debug.DrawLine(transform.position, hitPoint.position); float drawnLength = 2.0f; var endpoint = (hit.point) - drawnLength * hit.normal; ballAimer.SetPosition(0, transform.position); ballAimer.SetPosition(1, hitPoint.position); ballAimer.SetPosition(2, endpoint);
It seems like a Circlecast might be my best solution so could someone help me adjust my raycast to a circlecast? I tried but just couldn’t get it working correctly… I added all the parameters I believe I need and changed the Physics2D.Raycast like so:
RaycastHit2D hit = Physics2D.CircleCast(lineSpawn.transform.position, 1f, transform.up);
lineSpawn is a variable I created to have as the origin of the line that sits right infront of the ball. The problem is that the straight line changes angle towards the ball now (presumably because it’s creating a circle collider and somehow that isn’t working correctly?) In the photo below the line renderer should be in line with the white rectangle.
I know the main ball is slightly bigger as I was trying things out, but it happens no matter what. What can I do to fix this? I tried changing the radius in the circlecast but that just results in my original problem…