【问题标题】:How can I make an attraction point using Cannon.js如何使用 Cannon.js 制作吸引点
【发布时间】:2021-07-26 01:27:37
【问题描述】:

我正在使用 Three.js 和 Cannon.js。

另外,我正在尝试复制this object(多球一)。 基本上,球从其原点移动到压力点并停止,或围绕压力点旋转(这称为质量弹簧)。

目前我可以通过速度设置球的方向,但球不会停在压力点,距离越远,速度就越高(我需要恒定的速度)。

我在 Github 上问过这个问题,有人告诉我看看 this example。唯一的问题是它只围绕我正在寻找如何将球移动到听起来不一样的某个点的行星旋转。非常感谢任何帮助

【问题讨论】:

    标签: three.js cannon.js


    【解决方案1】:

    也许你需要一个像这样的物理模型:

    friction model
    m = 2 (it could be also m = 1 or m = 3 or whatever looks good)
    
    coefficients:
    cf = coefficient of friction
    cs = coefficient of spring
    
    Dynamics / update of position and velocity with time-increment dt
    
    x_cursor = x coordinate of cursor's position
    y_cursor = y coordinate of cursor's position
    
    x  =  x  +  dt * v_x
    y  =  y  +  dt * v_y
    v_norm = sqrt(v_x^2 + v_y^2)^(m-1)
    v_x  =  v_x  -  dt * cf * v_norm * v_x  -  dt * cs * ( x - x_cursor ) 
    v_y  =  v_y  -  dt * cf * v_norm * v_y  -  dt * cs * ( y - y_cursor )
    

    【讨论】:

    • 谢谢你的回答,我去看看
    猜你喜欢
    • 2018-01-10
    • 1970-01-01
    • 2022-09-30
    • 1970-01-01
    • 2019-09-27
    • 1970-01-01
    • 2013-04-29
    • 2011-10-27
    • 2021-12-20
    相关资源
    最近更新 更多