- Home /
How to use Vector3.Lerp without slow-down
I have a script that allows me to aim and it does a smooth transition between to Vector3's but sometimes the transitions slows down a lot. How do I make it so that it doesn't move so slow sometimes?
Here's my aiming code :
var Smoothing : float;
var HipPose : Vector3;
var AimPose : Vector3;
function Update () {
var newPosition : Vector3 = transform.position;
if(Input.GetButton("Fire2")){
transform.localPosition = AimPose;
Cam.fieldOfView = 40;
GunCam.fieldOfView = 20;
}
if(!Input.GetButton("Fire2")){
transform.localPosition = HipPose;
Cam.fieldOfView = 60;
GunCam.fieldOfView = 60;
}
transform.position = Vector3.Lerp(transform.position, newPosition, Smoothing * Time.deltaTime);
}
Answer by robertbu · Nov 12, 2013 at 04:55 PM
If you don't want your movement to be eased you can change from using Vector3.Lerp() to using Vector3.MoveTowards(). The value of 'Smoothing' will also have to change. Or as an alternate, you can change the last parameter of the Lerp() to using a timer and set the values so that they increase from 0.0 to 1.0. Your use of Lerp() here is a non-traditional use (though common in Unity code posted to this list). It really just takes a fractional bite out of the distance each frame. As the distance falls, the fraction is a smaller distance and therefore produces an eased movement.
Answer by felixpk · Nov 14, 2013 at 02:08 PM
Another aproach could be :
towerTop.rotation = Quaternion.Lerp(towerTop.rotation,Quaternion.LookRotation(leadDirection, transform.up),Time.deltaTime * damping);
And if you want to make it slowdown you just use:
towerTop.rotation = Quaternion.**SLerp**(towerTop.rotation,Quaternion.LookRotation(leadDirection, transform.up),Time.deltaTime * damping);
Answer by TSSTUDIOS · May 13, 2014 at 04:53 AM
why using a vectorin that case
var newPosition : Vector3 = transform.position;
id just do NewPosition = Transform.position;
Your answer
Follow this Question
Related Questions
How to smoothly rotate to certain directions using input axis 1 Answer
Vector3.Lerp works outside of Update() 3 Answers
Vector3.Lerp completing before t = 1? 2 Answers
3D menu camera rotation issue. 0 Answers
Moving the player toward a direction 1 Answer