关于绳子的缠绕和解开效果实现(不使用物理引擎)

关于绳子的缠绕和解开效果实现(不使用物理引擎)


                                                 在项目中可以体验绳子效果

                                       
现在只实现了规则四边形的的缠绕和解开(已在项目中使用)

                   

大概的思路:绳子在什么情况下会发生缠绕,什么情况会解开大概的思路:绳子在什么情况下会发生缠绕,什么情况会解开

  • 1,绳子在碰到一个突出的点(就是四边形的一个角时)会出现一个打弯的情况
  • 2,当前这段绳子(包括开始点和结束点)和任何四边形没有接触,则出现解开情况

基于以上这两点,开始准备相应的东西

  • 1,怎么指定发生碰撞?
  • 2,怎么处理打弯后绳子效果?
  • 3,怎么处理绳子解开效果?

碰撞相关:基于网格和直线的方式来检测碰撞,如果直线穿过了填充(需要一个编辑器去配置填充)的网格说明发生的碰撞

绳子相关:绳子是由一段一段的Section组成,当发生一个碰撞后,就会添加一个section,并把这个section设置成当前section,每次移动绳子时去检查,当前section是否还有碰撞,如果没有就触发解开绳子效果,删除当前section,并把上一次section设置为当前激活section

addSection: function(x,y,tx,ty,angle){
    if (!!this.lastSection) {
        this.lastSection.tex = tx;
        this.lastSection.tey = ty;
    }
    if (!!this.pRope) {
        this.pRope.stop();
    }
    this.lastSection = this._getsection();
    this.lastSection.x = x;
    this.lastSection.y = y;
    this.lastSection.tx = tx;
    this.lastSection.ty = ty;
    this.lastSection.angle = angle;
    this.activeSections.push(this.lastSection);
    let len = this.activeSections.length;
    this.lastSection.index = len - 1;
    if(len > 1) {
        this.llSection = this.activeSections[len - 2];
    } else {
        this.llSection = null;
    }
},


reduceSection: function(){
    if (!!this.pRope) {
        this.pRope.stop();
    }
    let len = this.activeSections.length;
    if(len <= 1) {
        this.llSection = null;
        return null;
    }
    let section = this.activeSections.pop();
    if (!!section) {
        section.isActive = false;
    }
    len = len - 1;
    this.lastSection = this.activeSections[len - 1];
    this.lastSection.clearEnd();
    if(len > 1) {
        this.llSection = this.activeSections[len - 2];
    } else {
        this.llSection = null;
    }
    return section;
},

有不对的地方请大佬指正
重力单摆

QQ交流群:1087682890

26赞

GIF图600k下载有点慢,刚开始看着会有点卡顿,下载完就ok 了

游戏效果很帅

谢谢!!!

厉害了!!

:14:,谢谢了

已更新重力单摆

给我玩湿了,6666666

:11::11::11::11::11:。。

牛逼了,:6:

捕捉大佬:2:

我猜你这个碰撞体不会是特制的吧 ,其实并不是看上去的口形状,而是只有4个顶点?
要是我,我一定这么干

肯定不是特制的,你看看上边游戏的很多中样式的碰撞,不是四个顶点,是网格

厉害了,这效果满分

终于发现为啥有怎么多人不想学物理,原来大家都在对抗牛顿。。。。。。

学习物理就是为了对抗牛顿(确信:14:

哈哈哈哈,你太有才了

感谢您的夸奖

这一个物体可以有多种碰撞结构嘛,我只是这样构思
能做成任意碰撞都生效当然更方便
我只是用偷懒的模式思考而已

:test:,大佬很强