Last active
February 23, 2022 01:01
-
-
Save 314pies/c379e8eb60d77b970644fb2428c53ded 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
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