TobiasWehrum / unity-utilities

A collection of Unity3D scripts I've been sharing between projects - open source, fully commented and with examples.
MIT License
276 stars 28 forks source link

EasedLerp extension methods for vectors #1

Closed oxysoft closed 8 years ago

oxysoft commented 8 years ago

Add extension methods to Vector3 for EasedLerpFactor so that we can do

follower.position = Vector3.EasedLerp(follower.position, mousePositionWorld, 0.75f);

instead of

float t = MathHelper.EasedLerpFactor(0.75f);
follower.position = Vector3.Lerp(follower.position, mousePositionWorld, t);

The same should be done for Vector2, and it would be handy too to add a EasedLerp method to MathHelper to perform the same lerping operation for single numbers.

e.g.

foo = MathHelper.EasedLerp(foo, targetFoo, 0.75f);
TobiasWehrum commented 8 years ago

I'm pretty sure I can't add static methods to existing unity classes, but adding those to MathHelper/UnityHelper sounds good to me.

oxysoft commented 8 years ago

Oh right good point, didn't think of that. What you could do is make it an instance method then

follower.position = follower.position.EasedLerp(mousePositionWorld, 0.75f);
TobiasWehrum commented 8 years ago

I wanted to stay as close to the existing lerp notation as possible.

Added: