# Non-linear LERPing

This topic is 3936 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a sprite I want to move between two positions. I have a timer controlling how long it takes, such that I may say go from point1 to point2 in 300ms. The two ways I am doing it now are: Clock -= DeltaMS (and is capped at zero time) Linear translation: Pos = Vector2.LERP(Start, End, 1.0f - Clock / TurnTime); Which gives, as expected, a smooth, constant movement over the TurnTime frame. Smooth translation: Same as Linear, except after I get Pos I then: Start = Pos; This gives a smoother transition as the sprite decelerates into the final spot. The problem is that it appears to get to the final spot fairly fast and ends up pausing for a moment before moving on. IE: I have a TurnTime that is 500ms. Every 500ms I set my sprite pos to a new location. The appearance is that the sprite zips to the new spot and pauses and then moves to the next spot. If the sprite is using a 500ms TurnTime to get from point1 to Point2, and the sprites position is changed every 500ms, I should expect constant motion. I think if I could use some kind of non-linear LERP it would look better. Maybe where the sprite didn't move so fast in the beginning, but not so slow in the end. Does anyone know of a good function I can use to pass into my LERP that will give a nice, smooth value?

##### Share on other sites
You could use the cosine function, or a spline of some sort.

let t = 1.0f - Clock / TurnTime

.5f*(1 - cosf(pi * t))

or

3*t*t - 2*t*t*t

should get the desired effect.

##### Share on other sites
The second one might work, id have to look at the curve, but the first one will not.

In the first example, if T is 0 or T is 1 (starting and ending time), then you have the Cos of PI or Cos of 0, both of which is 1.

So that function would go from LERP = 0 at T=0, and LERP = 0 at T = 1 with a max of LERP = .5 at T = .5. So Id start and end at the same place.

##### Share on other sites
Quote:
 Original post by TheSilverHammerThe second one might work, id have to look at the curve, but the first one will not.In the first example, if T is 0 or T is 1 (starting and ending time), then you have the Cos of PI or Cos of 0, both of which is 1.So that function would go from LERP = 0 at T=0, and LERP = 0 at T = 1 with a max of LERP = .5 at T = .5. So Id start and end at the same place.

I'm sure you can figure out how to adjust the formula to make it work properly, since you apparently have a pretty good idea of what a cosine function looks like :/

##### Share on other sites
Quote:
 Original post by TheSilverHammerIn the first example, if T is 0 or T is 1 (starting and ending time), then you have the Cos of PI or Cos of 0, both of which is 1.

The cosine of pi is -1. The other formula should be good enough for this purpose anyway.

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002292
×