I have a top down billiard game. And on click / tap the ball moves in the clicked direction like in the image below:
Now, I want a line to be drawn in the direction where the mouse is hovers or the finger is swiped, here is my update code:
void Update () {
//this should make the line, why not working?
Vector3 forward = transform.forward;
Debug.DrawRay(transform.position, forward);
Debug.DrawLine(transform.position, transform.position + forward * 10000);
if (Input.GetMouseButtonDown (0)) {
//
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100.0f)){
//
//
Vector3 startPos = transform.position;
Vector3 clickPos = new Vector3(hit.point.x, hit.point.y, transform.position.z);
Vector3 direction = Direction (clickPos - startPos);
//direction
rb.velocity = new Vector3(direction.x * 5, direction.y * 5, 0);
}
}
}
I tried DrawLine, Drawray, any ideas?
Debug
for drawing spatial user interfaces is the classGizmos
. Any calls to it need to be in theOnDrawGizmoz
event. \$\endgroup\$transform.forward
relative to your cueball is maybe downwards? \$\endgroup\$