Question by
Sawbones813 · Feb 15, 2016 at 05:06 AM ·
rotationtransformposition
My camera is moving away from the object it's rotating around, how do I fix this?
For some reason the distance between my camera and the object it's rotating around is getting larger.
using UnityEngine;
public class PlanetControls : MonoBehaviour {
public Transform cameraTransform;
public GameObject body;
public float speed = 10f;
void Start () {
cameraTransform.LookAt(body.transform.position);
}
void Update () {
Debug.Log(Vector3.Distance(cameraTransform.position, body.transform.position)); //Distance grows as time goes on
cameraTransform.position += (cameraTransform.right * speed * Time.deltaTime);
cameraTransform.LookAt(body.transform.position);
}
}
heirarchy.png
(2.5 kB)
Comment
Your answer
Follow this Question
Related Questions
Perfectly Syncing the rotation of two objects 0 Answers
How can I make an object transform to given position and rotation 2 Answers
Enemy not facing player when enter rotation orbit 0 Answers
Car Controls without physics. 1 Answer
How do I change the position of my player model after I rotate it so it's not teleporting? 0 Answers