Question by
burnfire · Nov 11, 2016 at 08:04 PM ·
errormovementcamera-movement
Camera moves well in game preview but not so well in actual game
As the title says, the camera in the project follows the object well in game view in unity editor, but won't work in the actual game file. In game file, only the LookAt function works, not the MoveTowards. Here is the script:
using UnityEngine;
using System.Collections;
public class MiscaCamera : MonoBehaviour {
public new Transform camera;
public Transform rb;
public float viteza;
Vector3 dif;
void Start () {
viteza = GetComponent<float>();
rb = GetComponent<Transform>();
camera = GetComponent<Transform>();
dif = camera.transform.position - rb.transform.position;
}
// Update is called once per frame
void FixedUpdate () {
camera.transform.LookAt(rb);
camera.transform.Translate(rb.transform.position - dif);
}
}
Where "viteza" means speed. I used this kind of movement because the object is set to move with time.deltaTime. Thanks.
Comment
Your answer
Follow this Question
Related Questions
How to make an object go the direction it is facing? (Im new) 0 Answers
How touch works 1 Answer
Cinemachine Track straight line movement not working 0 Answers
Issue with Jumping and Movement 1 Answer