Currently it just teleports the player to the position of the empty object. How can i make it smoothly move to the empty object?
var touchingLedge : boolean;
var player : GameObject;
var end : Transform;
var start : Transform;
function Update () {
if (touchingLedge == true)
player.transform.position = Vector3.Lerp(start.position, end.position, Time.time);
}
function OnTriggerEnter (hit : Collider)
{
if (hit.gameObject.tag == "Player")
touchingLedge = true;
yield WaitForSeconds(0.3);
touchingLedge = false;
}
Here’s a solution I ran across some time ago, likely from these boards. Lerp over time. I think it will work as you want it to:
//Declared somewhere near touchingLedge
var moving : boolean = false;
function Update () {
if (touchingLedge == true) {
//Last variable is seconds you want Lerp to last
StartCoroutine(MoveFromTo(start.position, end.position, 0.5f));
}
}
function MoveFromTo(pointA : Vector3, pointB : Vector3, time : float) {
if (!moving) { // Do nothing if already moving
moving = true; // Set flag to true
var t : float = 0f;
while (t < 1.0f) {
t += Time.deltaTime / time; // Sweeps from 0 to 1 in time seconds
transform.position = Vector3.Lerp(pointA, pointB, t); // Set position proportional to t
yield; // Leave the routine and return here in the next frame
}
moving = false; // Finished moving
}
}