Skip to content

Instantly share code, notes, and snippets.

@314pies
Last active April 4, 2022 00:42
Show Gist options
  • Save 314pies/303cdea7a678ee1a6bc57832b3366fb1 to your computer and use it in GitHub Desktop.
Save 314pies/303cdea7a678ee1a6bc57832b3366fb1 to your computer and use it in GitHub Desktop.
public void PokeRigidBody()
{
//Make sure to import TouchScreenWrap.cs first
if (TouchScreenWrap.touches.Length > 0)
{
var ray = cam.ScreenPointToRay(TouchScreenWrap.touches[0].position);
RaycastHit hit;
//Our finger poke on something with collider
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