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);
}
}
}
I've always thought Lerp needs some form of reference to Time.deltaTime. Have you tried altering the distCovered variable to: var distCovered = (Time.deltaTime - startTime) * speed;
– SubatomicHeroSame result...
– MrThunderocityHave you played with the speed variable? Changed its value to get a different result?
– SubatomicHeroYep, no change at all.
– MrThunderocity