- Home /
Path to path smoothing
Hi everyone,
I'm working on a game where I have a continuous random path around an sphere. Every time the spaceship reaches an end point, a new random position is chosen.
This works ok, but the movement is kinda jerky at the ends. Is there any way to smooth the movement acros those two directions? I realise that I've got to calculate the new point before it reaches the endpoint, which I've got working, I'm not sure however on how to smooth between the two paths.
This is my code so far:
Vector3 startVector; Vector3 endVector;
float animationTime; public float speed = 0.5f;
float minSpeed = 0.3f; float maxSpeed = 0.6f;
void Update () { animationTime = animationTime + 0.02f;
float actualSpeed = Mathf.Lerp(minSpeed, maxSpeed, speed);
//Check if we are at the target
if((actualSpeed * animationTime) >= 1)
{
animationTime = 0;
startVector = transform.position;
endVector = Random.onUnitSphere * 4.5f / 2;
}
else
{
transform.position = Vector3.Slerp(startVector, endVector, actualSpeed * animationTime);
}
}
Thanks!
Your answer
Follow this Question
Related Questions
Doesn't Add Rotation Over 180 2 Answers
Continously correct rotation 3 Answers
How to Slerp through values inside a 2D array ? 1 Answer
Smooth Extruded Mesh? 1 Answer
curved path, Slerp issue? 1 Answer