Jump to content
  • Advertisement
Sign in to follow this  
TheSilverHammer

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by TheSilverHammer
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.


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 this post


Link to post
Share on other sites
Quote:
Original post by TheSilverHammer
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.


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!