first please format your code next time, use the 1010 button to do so… sometimes it doesn’t work though se be sure to check that it works
basically when the user touches the screen the character will look at then proceed to walk to that position? the anwser is pretty simple
lets look how you got the player to look in that direction
void LookAtFinger () {
Ray ray = cam.ScreenToRay (Input.mousePosition) ;
RayCastHit hit ;
if (physics. RayCast (ray, out hit , Mathf.Infinity , detectorLayer ) {
transform.LookAt (hit.point);
transform.eularAngles = new vector3 (-90 , transform.eularAngles.y , 0 ) } }
here you get your screen coordinates for the user input then ray cast until you hit something, then rotate the character look at that point. this point we will call dest
now we got the direction of the dest, because… as you said the player is looking at it. so when we move the player in its forward direction , it will eventually reach it…
so all we do is once we have out direction move it forward
transform.position += Vector3.forward * transform.rotation * Time.deltaTime;
now your character should continue to move forward until it reaches dest, then we need to make sure it will stop at dest (and not spin around or something). so we need to check if the player is at dest, if so stop moving, if not coninue
var dest = hit.point;
if(Vector3.distance(dest,transform.position) > 0.0f) {
transform.position += Vector3.forward * transform.rotation * Time.deltaTime;
}
there we go… your character should now move to where ever the user has there finger on the screen
now there a’lot of ways you might use to actually move your character (e.g controller.Move), I’m just editing the position directly for simplicity and explanatory reasons. it doesn’t matter which you use.
Hope it helps