Need help with lerp dash
Hi everyone, I'm trying to make a dash script for my rigidbody 3d character. But instead of slowly lerping from point A to point B it kinda teleports . I need help to fix this. Thanks in Advance.
Here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Lerp : MonoBehaviour {
public Transform startMarker;
public Transform endMarker;
public float speed = 1.0F;
private float startTime;
private float journeyLength;
void Start() {
startTime = Time.time;
journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
}
void Update()
{
// Dash
if (Input.GetKeyDown (KeyCode.Space)) {
float distCovered = (Time.time - startTime) * speed;
float fracJourney = distCovered / journeyLength;
transform.position = Vector3.Lerp (startMarker.position, endMarker.position, fracJourney);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
fromtorotation inacurate Help fixing? 0 Answers
Attaching Light lerp to in-game clock 1 Answer