BugFix: 拖动木块时,幅度太大会左右摆动
This commit is contained in:
1 parent
7f1d935733
commit
745e727ef7
1 file changed
+8
@@ -1097,6 +1097,14 @@ l <p class="section-sub">力是物体对物体的作用,力不能脱离物体
|
||||
else vel = Math.min(0, vel + fricStep);
|
||||
}
|
||||
}
|
||||
// 拖拽时按距光标的剩余距离限制速度,越接近光标限速越低,
|
||||
// 避免速度过大冲过光标后弹簧反向拉回造成左右摆动
|
||||
if(dragging && moving){
|
||||
const pullNow = dragTargetX - (box.x + box.w / 2);
|
||||
const limitV = Math.abs(pullNow) * 0.18 + 0.5;
|
||||
if(vel > limitV) vel = limitV;
|
||||
else if(vel < -limitV) vel = -limitV;
|
||||
}
|
||||
if(moving){
|
||||
box.x += vel * 0.016 * 60;
|
||||
if(box.x < 20){ box.x = 20; vel = 0; moving = false; }
|
||||
|
||||
Reference in new issue
Block a user