初始静态的刚体被设置为动态后再改为静态无法被球体射线检测sweepSphere

Creator 版本: 3.8.8

  • 目标平台: PC Chrome 浏览器

  • 重现方式:用我提供的代码即可重现

  • 首个报错:无报错

  • 重现概率: 100%

需求:由于物体非常多至少30000+,因此无法让刚体一直处于动态,仅在需要时设置为动态,静置后再设置会静态。
实测30000+静态刚体性能可接受,并且用PhysicsSystem.instance.sweepSphere可以检测到静态刚体,性能依然可以接受。
但将刚体设置成动态后再设置回静态,sweepSphere就无法检测到了。
image


image

//球形射线检测到之后改为动态并击飞
const viewportRect = view.getViewportRect();

            const outRay = new geometry.Ray();

            this.camera.screenPointToRay(viewportRect.width/2,viewportRect.height/2, outRay);

            const result = PhysicsSystem.instance.sweepSphere(outRay, 0.5, 1<<1, 3, true);//球形射线检测

            if (result) {

                const fx = this.character.forward.clone();

                fx.y=0.2;

                PhysicsSystem.instance.sweepCastResults.forEach((element) => {

                    let inode=element.collider.node;

                    let ir=inode.getComponent(RigidBody);

                    if(ir.type==RigidBody.Type.STATIC){

                        ir.type=RigidBody.Type.DYNAMIC;//改为动态

                    }

                    this.dongqians.add(inode);

                    ir.setLinearVelocity(fx.clone().multiplyScalar(5));//施加线性速度

                });

            }

//检测到停止移动重新设置为静态
for (const qian of this.dongqians) {

            let sd = new Vec3();

            let rb=qian.getComponent(RigidBody);

            rb.getLinearVelocity(sd);

            if (sd.length() < 0.1) {//速度小于0.1

                this.dongqians.delete(qian);

                rb.type=RigidBody.Type.STATIC;//设置为静态

            }

        }