attempt fix internal edge collisions

This commit is contained in:
RandomityGuy 2022-12-12 01:42:12 +05:30
parent ef392a17b1
commit cfd40df7b6
2 changed files with 19 additions and 18 deletions

View file

@ -1046,21 +1046,19 @@ class Marble extends GameObject {
var isOnEdge:Bool = false; var isOnEdge:Bool = false;
for (i in 0...surface.indices.length) { for (j in 0...surface.indices.length) {
{ var thisVert = surface.points[surface.indices[j]];
var thisVert = surface.points[surface.indices[i]]; if (thisVert != lastVert) {
if (thisVert != lastVert) { var edgePlane = PlaneF.ThreePoints(toDifPoint(thisVert).add(polyPlane.getNormal()), toDifPoint(thisVert),
var edgePlane = PlaneF.ThreePoints(toDifPoint(thisVert).add(polyPlane.getNormal()), toDifPoint(thisVert), toDifPoint(lastVert));
toDifPoint(lastVert)); lastVert = thisVert;
lastVert = thisVert;
// if we are on the far side of the edge // if we are on the far side of the edge
if (edgePlane.getNormal().dot(toDifPoint(collisionPos)) + edgePlane.d < 0.0) if (edgePlane.getNormal().dot(toDifPoint(collisionPos)) + edgePlane.d < 0.0)
break; break;
}
} }
isOnEdge = i != surface.indices.length; isOnEdge = j != surface.indices.length;
} }
// If we're inside the poly, just get the position // If we're inside the poly, just get the position
@ -1084,7 +1082,7 @@ class Marble extends GameObject {
} }
var radSq = radius * radius; var radSq = radius * radius;
for (iter in 0...surface.indices.length) { for (iter in 0...surface.indices.length) {
var thisVert = surface.points[surface.indices[i]]; var thisVert = surface.points[surface.indices[iter]];
var vertDiff = lastVert.sub(thisVert); var vertDiff = lastVert.sub(thisVert);
var posDiff = position.sub(thisVert); var posDiff = position.sub(thisVert);

View file

@ -131,11 +131,14 @@ class Collision {
// } else // } else
var edgeDotAng = Math.acos(edgeDots[chosenEdge]); var edgeDotAng = Math.acos(edgeDots[chosenEdge]);
if (edgeDotAng < Math.PI / 12) { if (edgeDotAng < Math.PI / 12) {
if (edgeDotAng == 0) { // if (edgeDotAng == 0) {
res.normal = center.sub(res.point).normalized(); // res.normal = center.sub(res.point).normalized();
} else { // } else {
res.normal = normal; // edgeNormals[chosenEdge]; // res.normal = normal; // edgeNormals[chosenEdge];
} // }
res.point = null;
res.normal = null;
res.result = false;
} else { } else {
res.result = false; res.result = false;
res.normal = center.sub(res.point).normalized(); res.normal = center.sub(res.point).normalized();