# Move to object vector3.lerp help

I’m trying to have an object move to a position with the vector3.lerp. heres the code

``````using UnityEngine;
using System.Collections;

public class NPCJump : MonoBehaviour {
float startTime;
float duration = 1.0f;
public bool jump = false;
Vector3 startPoint;
Vector3 endPoint;

void LateUpdate () {
if(jump) {
startPoint = transform.position;
endPoint = new Vector3 (startPoint.x, startPoint.y * 5, startPoint.z);
startTime = Time.time;
transform.position = Vector3.Lerp(startPoint, endPoint, (Time.time - startTime) / duration);
jump = false;
}
}
}
``````

Instead of having the endPoint be linked to an object, I just want the endPoint to be some units above the startPoint. But I think I’m doing it wrong.

anybody have a better way of making him jump?

How about storing a 'jumpOffset' Vector3, which gets added to the 'stored position' every frame. That way, you can do something like this

``````Vector3 groundPosition = however you set that if the dude wasn't jumping;
Vector3 jumpOffset;
public float maxJump = 10;
bool isJumping = false;

``````

jumpOffset should be set at the top, so that it can be modified by things. Then, do your jumping in a coroutine-

``````IEnumerator DoJump(jumpTime)
{
float originalTime = jumpTime;
isJumping = true;
while(jumpTime > 0)
{
jumpTime -= Time.deltaTime;
float jumpProportion = jumpTime / originalTime;
float jumpHeight = maxHeight * Mathf.Sin(jumpProportion * Mathf.PI);
jumpOffset = new Vector3(0, jumpHeight, 0);
yield return null;
}
isJumping = false;
return null;
}

``````

Then call it like this-

``````if(thing should jump)
{
if(!isJumping)
{
StartCoroutine(DoJump(someTime));
}
}

``````

This, of course, provides totally unrealistic, yet predictable jumping behaviour. I think that's what you wanted?