Changing destination on a move object script

Hi, I’m trying to make a code that puts one object from one position to another, I have this code but I cannot change the end destination to my liking and I’m struggling to understand it. Any help would be appreciated. :slight_smile:

 enum MoveType {Time, Speed}

static var use : MoveObject;

function Awake () {
    if (use) {
        Debug.LogWarning("one only");
        return;
    }
    use = this;
}

// translates an object's position to another
function Translation (thisTransform : Transform, endPos : Vector3, value : float, moveType : MoveType) {
    yield Translation (thisTransform, thisTransform.position, thisTransform.position + endPos, value, moveType);
}

// smoothly moves and object from a point to another
function Translation (thisTransform : Transform, startPos : Vector3, endPos : Vector3, value : float, moveType : MoveType) {
    var rate = (moveType == MoveType.Time)? 1.0/value : 1.0/Vector3.Distance(startPos, endPos) * value;
    var t = 0.0;
    while (t < 1.0) {
        t += Time.deltaTime * rate;
        thisTransform.position = Vector3.Lerp(startPos, endPos, t);
        yield;
    }
}

// rotates to a certain limit given speed and time values
function Rotation (thisTransform : Transform, degrees : Vector3, time : float) {
    var startRotation = thisTransform.rotation;
    var endRotation = thisTransform.rotation * Quaternion.Euler(degrees);
    var rate = 1.0/time;
    var t = 0.0;
    while (t < 1.0) {
        t += Time.deltaTime * rate;
        thisTransform.rotation = Quaternion.Slerp(startRotation, endRotation, t);
        yield;
    }
}

thanks for your time.

After a quick glance it looks like endPos is the Vector3 variable that you need to change to set a different end destination… Your question is a bit unclear - have you been able to change the end position but just not to the correct position, or are you having trouble change it’s value altogether?