(我將不會百分之百地確定這個標籤是否與此相關)球員似乎與空氣相撞?
我在這裏令人難以置信的困惑。我試圖使用這個(簡化)模型讓我的弓箭手碰撞:
但是,正如你所看到的,我的弓箭手似乎在半空中相撞!我會理解它們是否會通過(例如,我沒有在我的碰撞模型中提供足夠的「分數」),但實際上似乎與任何東西碰撞都讓我感到莫名其妙。
我正在服務器上加載模型,代碼與我在客戶端顯示的代碼相同,所以不能成爲問題。無論如何,我有pastebinned it here。
然後,我將它添加到三個int[]
陣列,像這樣:
coordsx = new int[80 * 10];
coordsy = new int[80 * 10];
coordsz = new int[80 * 10];
for (javax.vecmath.Vector3f vec : m.getVertices()){ //Quick note: M is a model. As you can see, I'm just going through all the vertex positions.
coordsx[DELTA+(int) vec.x] = 1;
coordsy[DELTA+(int) vec.y] = 1;
coordsz[DELTA+(int) vec.z] = 1;
}
快速注:DELTA是((80 * 10)/2)
值或保存數學,400
。此外,我使用了三個int[]
而不是int[][][]
,因爲int[][][]
導致了我無法修復的OutOfMemory
。
現在,我已經得到了座標這些陣列,我使用這個代碼來檢查它:
for (int x = (int) (location.x + 1); x > location.x - 1; x--){
for (int y = (int) (location.y + 1); y > location.y - 1; y--){
for (int z = (int) (location.z + 1); z > location.z - 1; z--){
distancex = x;
distancez = z;
distancey = y;
try{
int i = 0;
if (owner.type == 0){
if (GameServer.DELTA + distancex > 0 && GameServer.DELTA + distancex < 800 && GameServer.coordsx[(int) (GameServer.DELTA + distancex)] == 1){
if (GameServer.DELTA + distancey > 0 && GameServer.DELTA + distancey < 800 && GameServer.coordsy[(int) (GameServer.DELTA + distancey)] == 1){
if (GameServer.DELTA + distancez > 0 && GameServer.DELTA + distancez < 800 && GameServer.coordsz[(int) (GameServer.DELTA + distancez)] == 1){
i = 1;
}
}
}
}
if (i == 1){
collision = true;
YDown = 0;
}
}catch (ArrayIndexOutOfBoundsException e1){
e1.printStackTrace();
}
}
}
}
if (collision){
System.out.println("Collision!");
}else{
System.out.println("No Collision!");
location.y = location.y-=YDown;
}
location
是弓箭手X,Y和Z的Vector3f
相對於船的位置 - 我已經使用de-bug消息檢查過了,位置確實正確地返回。
正如您所看到的,如果在被檢查的點的X,Y和Z位置都有一個座標,則變量i
僅被設置爲1。顯然,我也遍歷所有附近的座標,因爲我的球員不只是一個單一的點。
由於玩家似乎與空氣發生碰撞,所以顯然有些問題。但我找不到什麼。
我在這裏的正確軌道上,還是我做的一切都完全錯誤?如果我在正確的軌道上,那麼這裏出了什麼問題,我該如何解決它?
遊戲的難點在於測試和調試是非常地獄。然而,你的碰撞檢測代碼與OpenGL是完全分離的,所以它可以花費一些努力來設置一個測試理由,你可以在控制檯中運行,並對代碼進行基本的單元測試,看看在哪些情況下代碼不會做你期望的事情。這是無聊的工作,但比在運行遊戲中進行調試要容易得多 - 尤其是因爲運行的遊戲將會傳播無數的調試數字。 – Gimby 2015-02-10 12:56:19