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));

  

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM