在網上搜尋了一些資料,最後採用了obb的碰撞檢測,方法如下:
1 在3ds max中,將biped骨骼的大小設定恰當,在使用方框顯示骨骼的時候能比較準確的包圍住角色,如下圖:
然後選中所有的骨骼,使用maxscript指令碼匯出來。指令碼其實比較簡單,**如下:
-- file function
fn existfile fname = (getfiles fname).count != 0
-- main
filename = "f://work//myprojects//3dgame//3dsmax_data//fight_action_data.txt"
if existfile filename then deletefile filename
createfile filename
fp = openfile filename mode:"at"
for sel in selection do
(
-- get bounding box
bb = nodelocalboundingbox sel
-- print bb
-- print sel.transform
-- print "-------------"
position = (bb[2] + bb[1]) / 2
size = bb[2] - bb[1]
len = sel.transform[1].x ^ 2 + sel.transform[1].y ^ 2 + sel.transform[1].z ^ 2
len = len ^ 0.5
x1 = sel.transform[1].x / len
y1 = sel.transform[1].y / len
z1 = sel.transform[1].z / len
extent1 = (size.x * x1 + size.y * y1 + size.z * z1) / 2
len = sel.transform[2].x ^ 2 + sel.transform[2].y ^ 2 + sel.transform[2].z ^ 2
len = len ^ 0.5
x2 = sel.transform[2].x / len
y2 = sel.transform[2].y / len
z2 = sel.transform[2].z / len
extent2 = (size.x * x2 + size.y * y2 + size.z * z2) / 2
len = sel.transform[3].x ^ 2 + sel.transform[3].y ^ 2 + sel.transform[3].z ^ 2
len = len ^ 0.5
x3 = sel.transform[3].x / len
y3 = sel.transform[3].y / len
z3 = sel.transform[3].z / len
extent3 = (size.x * x3 + size.y * y3 + size.z * z3) / 2
print sel.name to:fp
print((extent1 as string) + "," + (extent2 as string) + "," + (extent3 as string)) to:fp
print((position.x as string) + "," + (position.z as string) + "," + ((-position.y) as string)) to:fp
print((x1 as string) + "," + (z1 as string) + "," + ((-y1) as string)) to:fp
print((x2 as string) + "," + (z2 as string) + "," + ((-y2) as string)) to:fp
print((x3 as string) + "," + (z3 as string) + "," + ((-y3) as string)) to:fp
)
close fp
生成的檔案格式如下:
"bip01"
"2.18656,2.18656,2.18656"
"0.583941,40.3044,-1.10637"
"0.555635,0.0,0.831426"
"0.831426,0.0,-0.555635"
"0.0,1.0,0.0"
"bip01 pelvis"
"6.1669,5.71345,5.46639"
"0.583941,40.3044,-1.10637"
"-1.21579e-006,1.0,6.67132e-007"
"0.481059,0.0,0.876688"
"0.876688,1.3868e-006,-0.481059"
…………
其中每個盒子的第二行資料就是盒子的半個長度,寬度和高度,和第四行至第六行的變換矩陣是一一對應的
第三行就是盒子的中心點位置,是全域性座標
第四行至第六行就是盒子在三個面方向上的標準變換矩陣了。
資料有了之後,就可以用obb碰撞演算法進行碰撞檢測了。
obb演算法可以參考:
或者他引用的乙個國外的**:
unity3d碰撞檢測
具體的一些,可以看 unity3d的 manual refrernce的東西,有幾個 在後面可以參考 幾個型別碰撞器 1.靜態碰撞器 就是只有碰撞器,但沒有剛體的 2.剛體碰撞器 帶rigidbody的碰撞器,這個是最基本的碰撞器 3.運動學剛體碰撞器 帶rigidbody,而且rigidbody的...
Unity3d 碰撞檢測
unity3d 主要由trigger和collison 兩種碰撞檢測 1 檢測trigger 雙方都有collider。雙方至少有乙個rigidbody 任意一方都可以 有乙個trigger 任意一方都可以 若只有乙個rigidbody,則碰撞時,該rigidbody一定要是運動的。碰撞後發出的on...
Unity 3D碰撞檢測
被呼叫的函式 碰撞器與觸發器 被呼叫的函式 以上兩個碰撞不能將各自的函式或引數改變,否則將出現以下錯誤 在unity3d中節點加入某某collider 2d元件則這個節點就是碰撞器 碰撞器分類 1.box collider 2d 矩形碰撞器 2.circle collider 2d 圓形碰撞器 3....