- Home /
How to move camera from point A to B
Hello!
I need to move the camera on the X axis for a trailer.
How do I move the camera on the x-axis from point a to b (has to take 5 seconds).
Thanks a lot!
Have you tried google-ing that before asking the question here?
There are ton's of anwers, about moving an object from A to B
Answer by Morgan · May 22, 2015 at 05:56 PM
Here's one way (this is JavaScript; it goes on the camera):
function moveMe( moveDistance : float, moveDuration : float) {
var startPosition : float = transform.position.x;
for (var d:float = 0; d <= 1; d += Time.deltaTime/moveDuration) {
transform.position.x = startPosition + moveDistance * d;
yield;
}
transform.position.x = startPosition + moveDistance; //Final position
}
//Then trigger this (in some script) with:
moveMe(10, 5); //First number is distance, pos or neg; second number is time in seconds
Welcome!
(You can do the equivalent in C# if you know C#.)
I realized that it doesn't really matter which language it is in. :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613200153im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Single Camera Lerping between three characters? (code provided) 0 Answers
Camera movement performs different with different inputs 0 Answers
How you change another script value smoothly on trigger 0 Answers
lerping transform.position on a camera 0 Answers
How Can I Linear Interpolate (Lerp) in Local Space? 2 Answers