- Home /
How to make a smooth transition between Vector3's
Hi, so I am trying to do a smooth transition between two positions whenever a controller isGrounded or not. But it doesn't seem to work. Can anyone help me with this please?
Here's my script:
var DefaultPose : Vector3;
var AirPose : Vector3;
private var CurrentPose : Vector3;
var PlayerCon : CharacterController;
var Smooth : float = Time.deltaTime * 3;
function Update () {
if(PlayerCon.isGrounded == false){
transform.localPosition = AirPose * Smooth;
}
else
if(PlayerCon.isGrounded == true){
transform.localPosition = DefaultPose * Smooth;
}
}
Have a look at Vector3.$$anonymous$$oveTowards, and try using smoothDeltaTime along with it.
Answer by mohitramani · Jun 27, 2013 at 10:59 AM
You could use either of the following: Vector3.Lerp(Vector3 from, Vector3 to, float time); Vector3.SLerp(Vector3 from, Vector3 to, float time); SmoothDamp (Vector3 current,Vector3 target, ref Vector3 currentVelocity, float smoothTime, float smoothTime);
Answer by rogeliopuig · Jun 27, 2013 at 10:57 AM
I'm not sure what you are trying to achieve but I wouldn't do it in the update Loop anyway, here's an approach.
float _smoothValue;
if (PlayerCon.isGrounded) {
transform.localPosition = Vector3.Lerp(transform.localPoistion, Airpose, _smoothValue);
}
else {
transform.localPosition = Vector3.Lerp(transform.localPoistion, DefaultPose, _smoothValue);
}
Time.deltaTime changes at every frame and you are initializing it at the very beggining. Not if you are using Lerp cause lerp interpolates between 0 and 1. If you give us more information on what you are trying to achieve we could help you more. Thumbs up if it helps!
Well, I am trying to make a parkour system, kinda, and I want my arms to have a smooth transition to the position they're gonna be in when you're in the air or when you're on the ground and they will lower. That's what I'm trying to achieve.
Your answer
