How to add aim lines in Unity2D

Hi All,

I’m currently trying to create a pool game. I’ve got the line renderer working so that whatever direction the player aims their ball in, a targeting line goes out and stops when it collides with any surface. I’m struggling to add a deflection line to show what direction the ball being hit will go though. I’ve searched all over and all forums are referring specifically to Unity3D and trying to adapt those to 2D just hasn’t worked for me! Here’s what I’ve got so far for the main line. Thanks!

        RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.up);

        hitPoint.position = hit.point;

        Debug.DrawLine(transform.position, hitPoint.position);

        lineRenderer.SetPosition(0, transform.position);
        lineRenderer.SetPosition(1, hitPoint.position);

can also use gl.lines, and few pages down this thread there is example for Vector3.Reflect

Thanks! I’d seen your posts before around here. The thing I struggle with is converting Physics.Raycast to Physics2D.Raycast… Have any insight into how onecould convert one to the other? Don’t seem to understand it much from my research. I’ve never worked in 3D so it’s very much uncharted territory.

added my old sourcecode here, was using 2D circlecast

1 Like

That makes so much sense now, thanks!