I resolved the question on how to draw a line, so here is the result:


So, now I want to create a line that shows the possible bounce off the wall (and the other ball).

Some suggested I use the Reflect method but it did not work, here is how I implemented it, script is attached to the white que ball:

        Ray ray2 = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit2;

        if (Physics.Raycast(ray2, out hit2, 100.0f)){

            //position of white wall
            Vector3 startPos = transform.position;
            //cliked position, translated to the table plane
            Vector3 clickPos2 = new Vector3(hit2.point.x, hit2.point.y, transform.position.z);
             //get direction from ball to clicked position
            Vector3 direction = Direction (clickPos2 - startPos);

              //so I simply should do I reflect, it gives me a bit odd results
            Vector3 reflectDir = Vector3.Reflect(direction, hit2.normal);

            //finally im drawing the line
            lineRenderer.SetPosition(0, startPos);

            Vector3 forward = transform.TransformDirection(direction) * 100;
            lineRenderer.SetPosition(1, forward);

            lineRenderer.SetPosition(2, hit2.point);

            lineRenderer.SetPosition(3, reflectDir);

Here is what this code gives me:


Any ideas on how to make it work?


  • \$\begingroup\$ Both Dropbox links are actually dead. \$\endgroup\$ – MAnd Oct 20 '15 at 5:07

Im not 100% sure, because your Dropbox link is dead, but I think your error is in the last line of your code. The lineRenderer connect Points in space and you need to convert your direction to a point.By adding a starting vector to your direction.

lineRenderer.SetPosition(3, reflectDir+hit2.point);
  • \$\begingroup\$ Looks like a good guess to me. \$\endgroup\$ – Steven Oct 20 '15 at 5:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.