I’ve seen a few posts about this but I’m new to scripting and having trouble figuring out how to implement some of the different solutions. I have a basic tap-to-touch function that I grabbed from here: Loading...
But when the character moves, it doesn’t change direction or orientation, regardless of where I tap. I’m trying to figure out if I need transform.LookAt or Quaternion.LookRotation, and how I would even implement it - or maybe it’s neither but I can’t figure it out regardless.
**I should clarify - it’s a 3d game with an isometric-style follow camera.
Here’s my current code - again, it’s just straight from the above link, and works great outside of the rotation issue. Thanks in advance.
public class TouchMovement : MonoBehaviour {
private bool flag = false;
private Vector3 endPoint;
public float duration = 50.0f;
private float yAxis;
void Start(){
yAxis = gameObject.transform.position.y;
}
void Update () {
if((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) || (Input.GetMouseButtonDown(0)))
{
RaycastHit hit;
Ray ray;
#if UNITY_EDITOR
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
#elif (UNITY_ANDROID || UNITY_IPHONE || UNITY_WP8)
#endif
if(Physics.Raycast(ray,out hit))
{
flag = true;
endPoint = hit.point;
endPoint.y = yAxis;
Debug.Log(endPoint);
}
}
if(flag && !Mathf.Approximately(gameObject.transform.position.magnitude, endPoint.magnitude)){ //&& !(V3Equal(transform.position, endPoint))){
gameObject.transform.position = Vector3.Lerp(gameObject.transform.position, endPoint, 1/(duration*(Vector3.Distance(gameObject.transform.position, endPoint))));
}
else if(flag && Mathf.Approximately(gameObject.transform.position.magnitude, endPoint.magnitude)) {
flag = false;
}
}
}