• Cocos Creator Spine的BoundingBoxAttachment碰撞检测


    版本2.3.4

    参考:

    CSDN spine使用BoundingBox实现游戏中的碰撞检测

    cocos creator 获取spine的boundingBox附件信息

    假如动画师在spine骨骼上画了一个BoundingBox,用于伤害判定的范围。

    在cocos中,从人物骨骼动画中获取这个hurt多边形,根据顶点创建一个PolygonCollider,并绑定到人物上,然后使用碰撞组件PolygonPolygon和Monster的BoxCollider进行碰撞检测

    //sk是人物的骨骼动画,获取骨骼动画上的挂件
    let attachment = this.sk.getAttachment('hero', "hurt")
    //获取hero的骨骼
    let slot = this.sk.findSlot("hero");
    //获取hurt的顶点数组
    let arr = {}
    let data = attachment.computeWorldVertices(slot, 0, attachment.worldVerticesLength, arr, 0, 2)
    console.log("多边形挂件:",attachment);
    console.log("多边形顶点:", arr);
    //为hero增加多边形Collider
     this.addComponent(cc.PolygonCollider);
    let poly:cc.PolygonCollider = this.getComponent(cc.PolygonCollider);
     for(let i=0;i<4;i++){
             poly.points[i].x = arr[i*2];
             poly.points[i].y = arr[i*2+1];
    }
    //hurt多边形碰撞体,和怪物mosnter的boxCollider进行碰撞检测(Monter.boxCollider为了测试方便保存的static变量)
    console.log("碰撞:", cc.Intersection.polygonPolygon((poly as any).world.points, (Monster.boxCollider as any).world.points));
    

      

  • 相关阅读:
    课后listview作业
    安卓sql
    activity带数据跳转
    安卓第四周作业
    15周作业
    十三周作业-集合
    十三周上机练习
    12周作业
    linux
    Questions.
  • 原文地址:https://www.cnblogs.com/gamedaybyday/p/13066821.html
Copyright © 2020-2023  润新知