猫史档案馆


岛3快速移动物体碰撞检测

用户:2333280823332808查看:0 回复:0 评论:0 创建时间:2024-06-24T14:56:00


众所周知,岛3的碰撞系统非常的,额,怎么说呢...对于超高速移动的物体检测非常差,基本等于没有

所以我郑重退出以下系统:

world.onTick(()=>{
    world.querySelectorAll(".physic").forEach((e)=>{
        e.k=new GameVector3(e.position.x-e.last_position.x,e.position.y-e.last_position.y,e.position.z-e.last_position.z)
        e.b=e.last_position
        e.last_position.copy(e.position)
    })
    world.coll=world.querySelectorAll(".physic")
    while(world.coll.length>0){
        e=world.coll.pop(0)
        world.coll.forEach(o=>{
            if((e.k.x-o.k.x)==0){
                if((-1*(e.bounds.x+o.bounds.x)-e.b.x+o.b.x)<=0&&((e.bounds.x+o.bounds.x)-e.b.x+o.b.x)>=0){
                    tx=[0,1]
                }else{
                    return
                }
            }else{
                tx=([(-1*(e.bounds.x+o.bounds.x)-e.b.x+o.b.x)/(e.k.x-o.k.x),
                ((e.bounds.x+o.bounds.x)-e.b.x+o.b.x)/(e.k.x-o.k.x)]).sort()
            }
            if((e.k.y-o.k.y)==0){
                if((-1*(e.bounds.y+o.bounds.y)-e.b.y+o.b.y)<=0&&((e.bounds.y+o.bounds.y)-e.b.y+o.b.y)>=0){
                    ty=[0,1]
                }else{
                    return
                }
            }else{
                ty=([(-1*(e.bounds.y+o.bounds.y)-e.b.y+o.b.y)/(e.k.y-o.k.y),
                ((e.bounds.y+o.bounds.y)-e.b.y+o.b.y)/(e.k.y-o.k.y)]).sort()
            }
            if((e.k.z-o.k.z)==0){
                if((-1*(e.bounds.z+o.bounds.z)-e.b.z+o.b.z)<=0&&((e.bounds.z+o.bounds.z)-e.b.z+o.b.z)>=0){
                    tz=[0,1]
                }else{
                    return
                }
            }else{
                tz=([(-1*(e.bounds.z+o.bounds.z)-e.b.z+o.b.z)/(e.k.z-o.k.z),
                ((e.bounds.z+o.bounds.z)-e.b.z+o.b.z)/(e.k.z-o.k.z)]).sort()
            }
            start_t=(([tx[0],ty[0],tz[0],0]).sort())[3]
            end_t=(([tx[1],ty[1],tz[1],1]).sort())[0]
            if(start_t<=end_t){
                if(e.on_coll){
                    e.on_coll({start_t,end_t,other:o})
                }
                if(o.on_coll){
                    o.on_coll({start_t,end_t,other:e})
                }
            }
        })
    }
})    
function vec_mul(vec,number){
    return new GameVector3(vec.x*number,vec.y*number,vec.z*number)
}
function not_zero(number){
    if(number==0){
        return 1
    }else{
        return number
    }
}
function set_physic(e){
    e.last_position=new GameVector3
    e.last_position.copy(e.position)
}

怎么用呢?

我们来看看

//在创建玩实体后
set_physic(e)
e.on_coll=({other})=>{
//自己写吧
}

谁来告诉我投稿插件哪里走?


回复

上一页1 页 / 共 0下一页