Prevent force-dragging bodies through other bodies with MatterJS

后端 未结 4 1677
醉梦人生
醉梦人生 2021-02-02 14:27

I\'m using MatterJs for a physics based game and have not found a solution for the problem of preventing bodies being force-dragged by the mouse through other bodies. If you dra

4条回答
  •  一向
    一向 (楼主)
    2021-02-02 15:28

    I would have managed the feature in another way:

    • No "drag" (so no continuos align of dragpoint with offset Vs dragged object)
    • On mouseDown the mouse pointer position give an oriented velocity vector for object to follow
    • On mouseUp reset your velocity vector
    • Let the matter simulation do the rest

提交回复
热议问题