- Home /
Lerp doesnt seem to work
i have a rope with 12 empty gameobjects with triggered colliders. when the user presses the up and down arrows the players position is changed to that of the triggered colliders and this allows me to climb up and down.
How the problem is that is travels up and and down too fast when holding down the buttons and i cant seem to slow this down...any ideas? tried lerping but that didnt fix it at all
EDIT: HERES IS MY CODE
// Moving up and down the Vine
if( Input.GetKey("up") )
{
playerTransform.position = Vector3.Lerp(playerTransform.position, curSegment.position, 50);
playerTransform.transform.parent = curSegment.transform;
}
Since the 't' parameter of lerp controls the resulting value it should normally work as intended if the formula for calculating 't' is chosen correctly. Could you provide some code so we can check what's going wrong?
You are using a fixed value of 50 for the third parameter, which must be between 0 and 1 (values >1 will be clamped to 1). The way that Lerp is "abused" most often is by applying a value of Time.deltatime*arbitraryFactor ins$$anonymous$$d (assu$$anonymous$$g yuo are doing this in Update(), otherwise it won't work), which will smoothly transform from parameter 1 towards parameter 2.
oh, i was doing it in another funciton. my own function. ah ok...im trying to get the slowest movement so i thought a high number will get me that result
Answer by flamy · Jun 25, 2012 at 12:32 PM
usually the t parameter of lerp will take a value of 0 to 1. so if you want your object to reach the destination in 3 seconds, what you should be doing is
first on keypress save the time,
float initialTime=Time.time;
and in update or somewhere call this,
float t=(Time.time-initialTime)/3.0f;
and pass the value to as the parameter to Lerp function.
so the general formulae should be
(finalTime-initialTime)/duration;
make sure that the initialTime is global and is set only when the keypress happens.
Your answer
Follow this Question
Related Questions
how to rope climb 0 Answers
Climbing up solution 0 Answers
How to climb a rope? 1 Answer
MoveTowards based on time 2 Answers
Movement (left/right) and jumping = laggy motions.. please help! 0 Answers