我在我的世界有幾個對象,有三種主要類型。首先是自我,即玩家,玩家不會移動,但是他們會旋轉。第二種是直線飛出用戶的子彈。第三個是目標,這些只是坐在某個地方,等待被擊中。爲什麼我的3D碰撞檢測工作不正常?
下面是我用做碰撞檢測代碼,它不工作:
foreach (GameObject go in bullets) {
float goRadius = go.Model.Meshes.Sum((x) => x.BoundingSphere.Radius) * go.Scale;
EnemyObject last = null;
Vector3 goRealPos = Vector3.Transform(go.Position, Matrix.CreateScale(go.Scale) * Matrix.CreateTranslation(go.Position) * Matrix.CreateRotationY(go.Rotation.Y));
foreach (EnemyObject eo in targets) {
float eoRadius = eo.Model.Meshes.Sum((x) => x.BoundingSphere.Radius) *eo.Scale;
if (Vector3.Distance(eo.Position, goRealPos) < eoRadius + goRadius) {
//collision has occured
if (!eo.TakeHit()) {
last = eo;
}
//remove bullet
toBeRemoved.Add(go);
break;
}
}
if (last != null) {
targets.Remove(last);
}
if (go.Position.Z > 2000 || go.Position.Z < -2000) {
toBeRemoved.Add(go);
}
}
誰能告訴我,爲什麼它不工作?
情況並非如此。我放慢了我的子彈爬行,我的目標是相當大的,但碰撞從未發生(根據我的數學),雖然我的眼睛看到它 – Malfist 2011-03-13 19:26:36