lerp won't interpolate slowly

After an unexpectedly long amount of time I got the lerp function to work, but not exactly how I wanted it to… Inputting “1” where “fracJourney” currently is will move the object like it should, but I want it to do so slowly. I incorporated some of the code from here:

I’ve also tried creating loops that increase (by a decimal value) “fracJourney” but for some reason they don’t work. Any help would be appreciated SOOOooOOoOoo much, I hate being stuck on something like this!

``````#pragma strict

// Movement speed in units/sec.
var speed = 1.0;

// Time when the movement started.
private var startTime: float;

// Total distance between the markers.
private var journeyLength: float;

var target : Transform;
var smooth = 5.0;

function Start () {

}

function Update () {

var currentResolution : Screen;
var centerPixel = Vector3 (currentResolution.width, currentResolution.height);

for (var touch : Touch in Input.touches) {

if (touch.phase == TouchPhase.Began) {

//Logs the first touch and then calculates a vector to start the "lerping" from.

var startingLoco = touch.position;
var newStartingX = startingLoco.x/currentResolution.width;
var newStartingY = startingLoco.y/currentResolution.height;
//var startMarker = Vector3(newStartingX, newStartingY, 0);

transform.position = Vector3(newStartingX, newStartingY, 0);
}

if (touch.phase == TouchPhase.Ended){

//Logs the last touch and then calculates a vector that I want to the attached GameObject to transform to.

var endingLoco = touch.position;
var newEndingX = endingLoco.x/currentResolution.width;
var newEndingY = endingLoco.y/currentResolution.height;
var endMarker : Vector3 = new Vector3(newEndingX, newEndingY, 0);
//transform.position = Vector3(newEndingX, newEndingY, 0);

startTime = Time.time;
var journeyLength = Vector3.Distance(transform.position, endMarker);

var distCovered = (Time.time - startTime) * speed;

// Fraction of journey completed = current distance divided by total distance.
var fracJourney = distCovered / journeyLength;

transform.position = Vector3.Lerp(transform.position, endMarker, fracJourney);

}
}

}
``````

Check the value of start time and also, difference of this (Time.time - startTime).

I think so, it would be some problem.

Also, check without use of speed. if result comes something then add speed according to movement you want to need.

Lerp is ment to linearly interpolate between two fix points. You use the current position as start value which will be different each iteration. That’s why you have a non linear movement.