Lerp help desperately needed.
I have a lerp script that I have attached to a button on the bottom of a lift shaft, which takes the lift up to a certain point. works perfectly.. What I want is a lerp script that I can apply to a button at the top to take the lift back down again to the start point. This is for VR interaction...below is lerp for going up.
Any help would be really greatly appreciated. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Lerp : MonoBehaviour
{
public GameObject MovingCube;
private Vector3 startPos;
private Vector3 endPos;
private float distance = 4.19f;
private float lerpTime = 10;
private float currentLerpTime = 0;
// Start is called before the first frame update
void Start()
{
startPos = MovingCube.transform.position;
endPos = MovingCube.transform.position + Vector3.up * distance;
}
// Update is called once per frame
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("Finger"))
{
currentLerpTime += Time.deltaTime;
if (currentLerpTime >= lerpTime){
currentLerpTime = lerpTime;
}
float Perc = currentLerpTime/lerpTime;
MovingCube.transform.position = Vector3.Lerp(startPos, endPos, Perc);
}
}
}
Answer by streeetwalker · Sep 25, 2020 at 05:37 PM
if you want to Lerp in the other direction, just flip your start and endpoints around. Perhaps that is not what you mean?
Answer by VertexDesign · Sep 25, 2020 at 06:11 PM
OMG!!!...how was I so stupid. I've been playing with the float distance, changing Vector.up to vector.down.
Streetwalker, you are an absolute star...can't thank you enough.
Superb :)
LOL - you're very kind. I don't know how many times the same thing still happens to me!
Your answer

Follow this Question
Related Questions
Switching platforms causes so many errors why? 0 Answers
Moveing through Plane changes velocity 0 Answers
Moving platform causing Janky movement 0 Answers
Camera for 2.5D 2P Platformer 0 Answers
Moving platform 0 Answers