# Vector3.Slerp is 'jumping' from the begining to end position

I simply want my ‘character’ to move upwards 10 meters when a racast hits a tagged object.

I’m using a Vector3.Slerp, i’ve tried AddForce, but found it too unpredictable.

My basic Slerp code is:

``````function Update () {

var x = transform.position.x;
var z = transform.position.z;
var y = transform.position.y + 10;

var end = Vector3(x, y, z);

rigidbody.velocity = Vector3(0, 0, 0);
transform.position = Vector3.Slerp(transform.position, end, Time.time * 0.5);

}
``````

The trouble is, the model ‘teleports’ from the starting position to the end position, no visible transition takes place!

It is a 3rd person game, my x, y, z variables make sure the character moves upwards relative to the current position of the character.

‘He’ has a rigidbody, NON-kinematic and uses gravity.

I tried temporarily disabling gravity, and also using Time.deltaTime in space of Time.time, the problem persists.

Anyone have any experience with this? Or know a better way to move the character?

Thanks as always for your help, Tom

Lerp and Slerp functions take a value between 0 and 1. I think of this as the weight(and inverse weight) given to each vector v1 and v2 in…
Vector3 v = Vector3.Lerp(v1, v2, weight); // where if, weight = .25 → v = (1-.25)*v1 + (.25)*v2

so before you enable Update you need to save the start time, subtract the current time from the start time, and divide by the duration over which you would like to animate.

``````public class CharacterMove : Monobehaviour {
public float moveSpeed;

public void Awake() { enabled = false; }

float startTime, duration;
Vector3 startPoint, endPoint;
public void StartMove(Vector3 endPoint) {
// pre calc all the lerp parameters
startPoint = transform.position;
this.endPoint = endPoint;
duration = (endPoint - startPoint).magnitude/moveSpeed;
startTime = Time.time;

enabled = true; // start updating the lerp
}
public void Update() {
float time = Time.time-startTime; // time since start

// interpolate position
transform.position = Vector3.Lerp(startPoint, endPoint, time/duration);

// full interpolation achieved
if(time > duration) enabled = false;
}
``````

This is just off the top of my head so there may be bugs but the comments explain what you are doing. If you would rather not split this move operation into a two separate function you need to learn about coroutines and IEnumerator functions.

Try using Vector3.Lerp instead