- Home /
Accelerating an object for a brief time then back to normal speed
So I basically want to have an object at a set speed which at a press of a button will have a smooth acceleration boost for 2sec then drop back down to its normal speed
I've tried a simple way which basically changes the speed by a multiple then returning it back to its original speed but that messes with the lerp function I use to have a smooth travel by jerking the object backwards to a earlier position.
journeyLength = Vector3.Distance(startPoint, endPoint);
if(acceleration){
var distCovered = (Time.time - startTime) * speed * 2;
}
else{
var distCovered = (Time.time - startTime) * speed;
}
var fracJourney = distCovered / journeyLength;
transform.position = Vector3.Lerp(startPoint, endPoint, fracJourney);
Answer by Kiloblargh · Nov 26, 2013 at 08:28 PM
You're not doubling the speed, you're doubling the "distance covered" and placing the object where it would be had it been traveling that fast since it started.
You need to scrap your approach and use the more traditional
Transform.Translate (Time.deltaTime direction speed).
If you don't want the speed boost to be instantaneous, then you should use SmoothDamp on the speed variable.
Your answer
Follow this Question
Related Questions
Smoothly moving object along 1 axis 1 Answer
Smooth Lerp movement? 1 Answer
Lerp has some bumping effect 1 Answer
anyone can explain to me why I can't rotate continuously an object ? 1 Answer