I’v been going by multiple tutorials and scripts to come up with this:
here is what I have so far
Code (CSharp):
using System.Collections;
using System.Collections.Generic;
using System.Runtime;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Events;
public class aim : MonoBehaviour
{
public Rigidbody rb;
public int clickForce = 10;
public bool strikeBall;
public float target;
private RayCastHit;
void start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
if (Physics.RayCast(out hit))
{
Target = RayCast; hitPoint;
}
if (strikeBall)
{
rb.AddForce(target * clickForce);
}
}
}
The intent is to use raycast to set a target position on x and y then I press the ui button to send a pool ball towards set target but I’m not quite sure how to use raycast. Also I want to lock the cue ball on the zed axis I’m working I 2D.