hello all. I managed to find a script that works for my billiards game to be used to hit the cue ball.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class aim : MonoBehaviour
{
public Rigidbody rb;
public int clickForce = 10;
public bool strikeBall;
void start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var mouseDir = mousePos - gameObject.transform.position;
mouseDir.z = 0.0f;
mouseDir = mouseDir.normalized;
if (strikeBall = true)
{
rb.AddForce(mouseDir * clickForce);
}
}
}
I added that bool and if statement and enable the bool in my ui button.
intent was for the player to hit the ui button to send cue ball to last clicked position.
instead the ball adds force to position of the mouse cursor without pressing the ui button