Quadratic Bezier Curves feature #30
Replies: 3 comments
-
Cool, thanks for sharing! This Bezier movement method can be a good alternative for DOJump() that works in any orientation. I modified your code slightly to prevent a delegate memory allocation. My code uses a hack to store the controlValue in the internal variable, so this should be added inside PrimeTween's source code, in the TweenMethods.cs class, for example. public static Tween PositionBezier([NotNull] Transform target, Vector3 startValue, Vector3 controlValue, Vector3 endValue, float duration, Ease ease = Ease.Default, int cycles = 1, CycleMode cycleMode = CycleMode.Restart, float startDelay = 0, float endDelay = 0, bool useUnscaledTime = false) {
var settings = new TweenSettings<Vector3>(startValue, endValue, duration, ease, cycles, cycleMode, startDelay, endDelay, useUnscaledTime);
var result = animate(target, ref settings, t => {
var _controlValue = t.prevVal.Vector3Val; // hack: retrieve the controlValue from prevVal
(t.target as Transform).position = Bezier(t.startValue.Vector3Val, _controlValue, t.endValue.Vector3Val, t.easedInterpolationFactor);
}, t => (t.target as Transform).position.ToContainer());
result.tween.prevVal = controlValue.ToContainer(); // hack: store controlValue in prevVal because prevVal is only used in Custom_internal()
return result;
}
static Vector3 Bezier(Vector3 start, Vector3 control, Vector3 end, float t) {
float u = 1 - t;
float tt = t * t;
float uu = u * u;
Vector3 p = uu * start;
p += 2 * u * t * control;
p += tt * end;
return p;
} I'll consider adding this feature to PrimeTween in the future. Huge thanks for the idea! |
Beta Was this translation helpful? Give feedback.
-
For DoJump() i wrote my own too. Hope it helps.
|
Beta Was this translation helpful? Give feedback.
-
For DoShake()
|
Beta Was this translation helpful? Give feedback.
-
I wrote my own Quadratic Bezier Curves extension.
I'd really appreciate this feature if you could manage to add it.
Beta Was this translation helpful? Give feedback.
All reactions