Skip to content

Instantly share code, notes, and snippets.

@314pies
Created April 2, 2022 18:04
Show Gist options
  • Save 314pies/250b42787437b6b9a892283ca34b1ed8 to your computer and use it in GitHub Desktop.
Save 314pies/250b42787437b6b9a892283ca34b1ed8 to your computer and use it in GitHub Desktop.
var ray = cam.ScreenPointToRay(TouchScreenWrap.touches[0].position);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
if (hit.transform.GetComponent<Rigidbody>() != null)
{
Vector3 offSet = hit.transform.position - cam.transform.position;
hit.transform.GetComponent<Rigidbody>().AddForce(offSet.normalized * Force, ForceMode.VelocityChange);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment