hello all. I am working on this script for a pool game. I’m trying to set target position to mouse click and then hit ui button to send cue ball towards target position. problem is bool is enabled when I click mouse button not the ui button and I am not sure what the target position is being set to but its not the mouse position I intended.
just need to now how to get the target position in the console view or draw a line to it or whatever I need to do to find out where I am sending the ball.
public class aim : MonoBehaviour
{
public Rigidbody rb;
public bool strikeBall;
private Vector3 targetPos;
void start()
{
rb = GetComponent<Rigidbody>();
strikeBall = false;
}
void FixedUpdate()
{
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var mouseDir = mousePos;
mouseDir.z = 0.0f;
mouseDir = mouseDir.normalized;
if (Input.GetMouseButtonDown(0))
{
targetPos = mousePos;
}
if (strikeBall)
{
rb.AddForce(targetPos, ForceMode.Impulse);
}
}
}
any input is appreciated.