Skip to content

Instantly share code, notes, and snippets.

@314pies
Last active February 23, 2022 01:01
Show Gist options
  • Save 314pies/c379e8eb60d77b970644fb2428c53ded to your computer and use it in GitHub Desktop.
Save 314pies/c379e8eb60d77b970644fb2428c53ded to your computer and use it in GitHub Desktop.
void Update()
{
foreach (Touch _touch in TouchScreenInputWrapper.touches)
{
if (_touch.phase == TouchPhase.Began) {
Ray ray = Camera.main.ScreenPointToRay(_touch.position);
//This can show the ray in the editor scene windows.
Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow, duration: 3);
RaycastHit hit;
Physics.Raycast(ray: ray, hitInfo: out hit, maxDistance: 100);
//This will be the destination position for the player
Vector3 targetPosition = hit.point;
//After getting the destination position, you may want to use Transform.LookAt() to face the destination,
//and use Transform.foward to get the foword vector, and then apply it as the force for rigidbody
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment