Question by
KamiSama00 · Nov 03, 2019 at 11:51 PM ·
c#unity 5transformprogramminglerp
Lerping Camera Between Two Points
Hello Com,
I'm attempting to lerp my camera between two transforms. This is the script I currently have
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class camTransition : MonoBehaviour
{
public Transform startMarker;
public Transform endMarker;
public float speed;
public float startTime;
public float journeyLength;
public testController controller;
// Start is called before the first frame update
void Start()
{
//startTime = Time.time;
//journeyLength = Vector3.Distance(endMarker.position, startMarker.position);
}
// Update is called once per frame
void LateUpdate()
{
if (controller.isShooting == true)
{
float distCovered = (Time.time - startTime) * speed;
float fractionOfJourney = distCovered / journeyLength;
transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fractionOfJourney);
}
else if (controller.isShooting == false)
{
float distCovered = (Time.time - startTime) * speed;
float fractionOfJourney = distCovered / journeyLength;
transform.position = Vector3.Lerp(endMarker.position, startMarker.position, fractionOfJourney);
}
}
}
I just copied the method and changed it from B to A and it kind of works. When I start the game it has a nice smooth transition from B to A, however when I call it with mouse down and up it kind of just jumps to the transform its moving to. Any direction on where I can find a fix for this.
Thanks In Advanced, Prometheus
Comment
what do you mean by call it with on mouse down and on mouse up? you have that exact code in a method?
Yea, it works it just not lerping smoothing, moving to the exact transform.
can you post the exact code you are using in the separate method?