Last active
April 4, 2022 00:42
-
-
Save 314pies/303cdea7a678ee1a6bc57832b3366fb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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