所以我正在做一个简单的碰撞检测,其中玩家每次更新时都会向下移动 3 而不是在地面上,但是当它在地面上时,它会移动它的位置和地面的差异。但我越来越紧张(它上下移动太多,而且不是完全处于静止状态)。
我的问题是:如何让这段代码正确计算差异?
Vector3f pos = new Vector3f(25,-50,25);
//Vector3f pos = new Vector3f(25,-50,25); isn't actually in the update method,
//but is in the object's constructer.
onGround = false;
Vector3f projPos = new Vector3f(pos);
projPos.y += fallSpeed;
//get a vector of all the triangles touching the player
Vector<Tri> tris = getTrisTouching(pos);
float minY;
//make it so if we don't have a list we don't get tossed into infinity
if(tris.size() > 0) minY = Float.POSITIVE_INFINITY;
else minY = 0;
for(int i = 0; i < tris.size(); i++){
Tri tri = tris.get(i);
if(projPos.y + radius <= tri.max.y){
float difference = tri.min.y - projPos.y;
if(difference < minY) minY = difference;
onGround = true;
}
}
if(onGround){
pos.y = minY;
}
else{
pos.y = projPos.y;
}