Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

水果碰撞部分重叠如何处理?? #3

Open
yxf14789632 opened this issue Aug 7, 2024 · 2 comments
Open

水果碰撞部分重叠如何处理?? #3

yxf14789632 opened this issue Aug 7, 2024 · 2 comments

Comments

@yxf14789632
Copy link

yxf14789632 commented Aug 7, 2024

测试发现水果会碰撞 粒子边界会有一点重叠的情况,大佬 这个如何解决 需要自己在onCollisionStart额外处理么 有没有其他方法
image

@chocho-1115
Copy link
Collaborator

我做了如下几个方面的尝试:

修改重力

gravity:{ 
      x: 0,
      y: 1 //  原来是3
  },

然后一次添加200个水果

let num = 0
let timer = setInterval(()=>{
    num++
    if(num>100) {
        clearInterval(timer)
        return
    }
    this.createFruite(x,y,false)
},200)

重叠现象好很多了,但是水果掉落速度回更慢一些

修改刚体物理属性

这里面的物理引擎是用的MatterJs
在物理引擎demo中 我找到了这个示例:https://brm.io/matter-js/demo/#stress2
示例中底层刚体也存在重叠的现象

另外在文档中 我找到了刚体的slop属性
https://brm.io/matter-js/docs/classes/Body.html#property_slop

于是我在本地运行了示例stress2 并在代码中添加了slop参数:

    // scene code
    var stack = Composites.stack(100, 600 - 25 - 18 * 25, 25, 18, 0, 0, function(x, y) {
        return Bodies.rectangle(x, y, 25, 25, {
            slop: 0.001, // 默认 0.05
            restitution: 0
        });
    });

并没有什么明显的改变...
将slop值改为0后,一堆刚体像果冻一样 一直动,没有停止。而且文档里有这样一句:
This is required for proper collision response, including friction and restitution effects.
所以设置为0 并不合适。

@yxf14789632
Copy link
Author

yxf14789632 commented Aug 8, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants