- Home /
Walk where I tap in Android
So I wanna make a game where the camera is above you locked in position and you can only move in the camera zone, so how do I make it so wherever you tap you run to?
I'm really sorry but this isn't a place where we write code for you :)
How I would do it is check other questions of the same nature and then try to break my big problem into smaller ones. So you need an isometric camera following the character?
Then check about raycasting, and mouse position, this may help:
using UnityEngine;
using System.Collections;
public class targetmove : $$anonymous$$onoBehaviour
{
Vector3 newPosition;
void Start () {
newPosition = transform.position;
}
void Update()
{
if (Input.Get$$anonymous$$ouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
newPosition = hit.point;
transform.position = newPosition;
}
}
}
}
So yeah you get the idea!
Answer by rmassanet · Jul 19, 2016 at 07:40 AM
In order to do that, your character needs to have a NavMeshAgent attached, and you need to define a NavMesh (check online tutorials on how to do that). Then, as pointed out by @ahaykal, you need to raycast using the touch screen position, get the intersection with the NavMesh object, and finally tell your NavMeshAgent to move there.