Answer the question
In order to leave comments, you need to log in
How to make the camera move in the direction of view?
How to make the camera move in the direction of view?
I tried from point to point, but when moving from one point to another, it starts to fly along an incomprehensible trajectory.
I used LookAt to point the camera at a point.
using UnityEngine;
using System.Collections;
public class camera : MonoBehaviour {
public GameObject point;
public GameObject point2;
public float speed;
public bool touch;
Vector3 vec;
Vector3 moveDirection;
void Start () {
touch = false;
vec = point.transform.position;
transform.LookAt (vec);
}
// Update is called once per frame
void FixedUpdate () {
if (!touch) {
transform.Translate (Vector3.Normalize (vec - transform.position) * Time.deltaTime * speed);
//transform.LookAt (vec);
Debug.Log (touch);
} else {
Debug.Log(touch);
//transform.Translate (Vector3.Normalize (vec - transform.position) * Time.deltaTime * speed);
transform.Rotate(new Vector3(0,-0.8f,0)* Time.deltaTime * speed);
if(Mathf.Abs(transform.rotation.y) > 0.6 && Mathf.Abs(transform.rotation.y) < 0.7)
{
touch = false;
vec = point2.transform.position;
transform.LookAt (vec);
}
// Debug.Log("rot : " + transform.rotation.x);
// Debug.Log("rot : " + transform.rotation.y);
//Debug.Log("rot : " + transform.rotation.z);
// Debug.Log("loc : " + transform.localRotation);
/*transform.LookAt (vec);
Debug.Log("dw");
touch = false;
vec = point2.transform.position;*/
}
}
void OnTriggerEnter(Collider camer)
{
touch = true;
//Debug.Log("dwad");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question