Movement of camera over time
Im using the code below to try and move the camera from one location to another however it also changes the x and z values, what is best way to change a camera say from y 10 to 0.5 over 2 seconds, thanks! update: It works as expected when the camera has no parent, when its the child of a player controller, the x and z are changed.
public class CameraZoom : MonoBehaviour {
public float startY=10f;
public float speedSecs=12f;
public float ynow=0;
private Vector3 updatePos;
private Vector3 startPos;
void awake() {
}
// Use this for initialization
void Start () {
startPos = (Vector3.up * startY);
updatePos =(Vector3.up * 0.5f);
}
// Update is called once per frame
void Update () {
}
void FixedUpdate() {
if ( ynow<speedSecs) {
Debug.Log ("camera update! " + Mathf.Lerp(startY, 0.5f, ynow));
ynow += Time.deltaTime;
transform.position = ( Vector3.Lerp(startPos , updatePos, ynow/speedSecs));
}
}
}
Answer by dappledore · Nov 24, 2015 at 07:22 AM
I solved this myself, I changed transform.position to transform.localPosition
Your answer
Follow this Question
Related Questions
Third Person Camera - primary orbit script logic keeps overriding other position logic 2 Answers
My camera follows my player so that the camera goes inside the player. What can I do? 0 Answers
How to make camera rotate spherically around an object 0 Answers
So i am making an Android game in which i want the Camera to follow the Character ONLY on the Z-Axis 1 Answer