明明碰撞了,碰撞检测却检测不到

  • Creator 版本: 3.5.1

  • 目标平台: google chrome浏览器

  • 重现方式:

  • 首个报错:

  • 之前哪个版本是正常的:

  • 手机型号:

  • 手机浏览器:

  • 编辑器操作系统:

  • 重现概率: 80%以上

对碰撞题分组player和ground,在项目设置里设置两者碰撞。在游戏一开始,两个物体是碰撞的,也检测到了,然后player的位置就停在ground表面。当我再次对player做position向上再向下移动时,向下移动再次碰撞ground,但是会直接穿过ground,碰撞检测也没有检测到碰撞。
在player起跳时,ground会在update函数中向左移动位置。





微信截图_20220708111121
有时候player起跳能检测到碰撞,有时候又不能,这到底为什么?是我物体移动太快了?

是不是因为玩家的刚体休眠了,你唤醒试试

你试着用物理事件来移动,而不是在update里面改变position来移动物体… :roll_eyes:

开启了物理,就不要随便动postion。否则后果很严重 :grinning:

物理移动,player做向上运动,再向下运动,这个时间也是ground移动的时间。那我怎么一致player和ground的运动时间,player设置为 Dynamic,我给他一个力,让它向上运动,然后重力下落,但是player的运动时间我不知道怎么同步给ground

还是这种跳一跳动作不适合使用物理引擎

两个物体给相同的力应该运动时间是一样的吧,不太了解具体是一个什么样的表现,是要让ground跟着player一起动吗…

我根据碰撞检测把两个物体的速度全都设置为0,可以同步,但是有个问题,我这ground就是跑酷类游戏的背景地板,第一个ground已经在屏幕外,我现在想设置第一个ground的位置在第二个ground的右边,达到无缝连接。我setposition无效,改变不了位置。

for (let j = 0; j < this.mapArray.length; j++) {

        const map:Node = this.mapArray[j];

        const mapRigid:RigidBody2D = map.getComponent(RigidBody2D);

        mapRigid.linearVelocity = v2(0, 0);

    }

    for (let k = 0; k < this.mapArray.length; k++) {

        const map:Node = this.mapArray[k];

       

        const map1Transform: UITransform = map.getComponent(UITransform);

        console.log("map.position.x = ", map.position.x + map1Transform.width*0.5);

        console.log("left x = ", -this.viewSize.width*0.5);

        if (map.position.x + map1Transform.width*0.5 <= -this.viewSize.width*0.5) {

            let nextMap:Node = this.mapArray[1];

            if (k == 1) {

                nextMap = this.mapArray[0];

            }

            const mapTransform: UITransform = nextMap.getComponent(UITransform);

            map.setPosition(nextMap.position.x + mapTransform.width, 0, 0);

            console.log("map x = ", nextMap.position.x + mapTransform.width);

        }

    }

还是自己写矩形区域碰撞吧

如何用物理事件进行移动啊,请教一下。v:wei_wuxing