鼠标跟随器缓入/缓出
那里有很多 mousefollower 教程。它们中的大多数都具有用于缓和运动的简单公式:
x += (tx - x) / interp;
y += (ty - y) / interp;
(tx = 目标位置,x = 实际位置,interp > 1)
这使得从动件在开始时速度非常快,然后缓慢减速到目标位置。
我必须如何更改公式,以便我可以定义自定义加速度、自定义减速度以及两者之间运动的最大速度?一开始我会很高兴能有额外的加速。
谢谢!
汉斯
There are a lot of mousefollower tutorials out there. Most of them feature a simple formula for easing the motion:
x += (tx - x) / interp;
y += (ty - y) / interp;
(tx = target position, x = actual position, interp > 1)
This makes the follower go very fast in the beginning, then decelerate slowly to the target position.
How do i have to change the formular, so that i can define a custom acceleration, custom deceleration and a maxspeed for the movement in between? For the very beginning i'd be happy with an added acceleration at all.
Thanks!
Hans
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
加速度是速度随时间的变化。因此,在一维中,要应用恒定速度,您需要执行以下操作:
其中:
a
是加速度(常数)v
是速度x
> 是 x 位置dt
是时间步长,即更新之间的时间。您可以执行类似的减速操作,但
a
现在将为负数。要设置最大速度,您只需对
v
进行条件检查,可能是:其中
v_max
是允许的最大速度(常数)。在 2D 中,您需要考虑行进方向:
我将让您计算
theta
...Acceleration is the change in velocity over time. So in 1D, to apply a constant velocity, you'd do:
where:
a
is the acceleration (a constant)v
is the velocityx
is the x-positiondt
is the timestep, i.e. the time between updatesYou'd do something similar for deceleration, except that
a
would now be negative.To set a maximum velocity, you simply need to a conditional check on
v
, maybe:where
v_max
is your maximum allowed velocity (a constant).In 2D, you'd need to take into account the direction of travel:
I'll leave it to you to calculate
theta
...